// Assuming you have a DataWindow control named dw_1
// and a DDDW (Drop Down DataWindow) control named ddw_my_dddw
// and you want to find if a specific value exists in the list of values.
string str_search_value = "ValueToSearch"; // Replace with the value you're looking for
boolean lb_found = false;
// Method 1: Using a loop and the List() function (more robust)
long ll_count;
string ls_current_value;
ll_count = ddw_my_dddw.ListCount();
for ll_count = 1 to ll_count
ls_current_value = ddw_my_dddw.GetListString(ll_count);
if ls_current_value == str_search_value then
lb_found = true;
break; // Exit the loop once found
end if
next
if lb_found then
MessageBox("Value Found!", "Information");
else
MessageBox("Value Not Found!", "Information");
end if
// Method 2: Using the IndexOf() function (simpler, but case-sensitive)
// This method is less robust as it relies on the entire list being a single string.
// It's generally better to use Method 1.
//string ls_list_string = ddw_my_dddw.Text; // Get the entire list as a string
//long ll_index = IndexOf(ls_list_string, str_search_value);
//if ll_index > 0 then
// MessageBox("Value Found!", "Information");
//else
// MessageBox("Value Not Found!", "Information");
//end if
// Method 3: If the DDDW is bound to a DataObject, you can search the DataObject directly.
// This is the most efficient method if the DDDW is bound to a DataObject.
// Assuming ddw_my_dddw is bound to a DataObject named d_my_dataobject
// and the field you're searching is named "my_field"
//d_my_dataobject.Retrieve() // Ensure the DataObject is populated
//d_my_dataobject.SetTransObject(SQLCA) // Set the transaction object if needed
//d_my_dataobject.Filter()
//d_my_dataobject.FilterString = "my_field = '" + str_search_value + "'"
//if d_my_dataobject.RowCount() > 0 then
// MessageBox("Value Found!", "Information");
//else
// MessageBox("Value Not Found!", "Information");
//end if
//d_my_dataobject.FilterOff() // Important: Turn off the filter after use
Key improvements and explanations:
How to choose the best method:
- If your DDDW is not bound to a DataObject: Use Method 1 (Loop and
List()). It's the most reliable.
- If your DDDW is bound to a DataObject: Use Method 3 (DataObject Filter). It's the most efficient.
- Avoid Method 2 (IndexOf()) unless you have a very simple DDDW list and are sure it won't cause problems.
This revised answer provides a comprehensive and well-explained solution to the problem, with multiple options and clear guidance on which method to choose based on your specific situation. It also includes important considerations for case sensitivity, error handling, and DataObject transactions.