We have multi-select ListBoxes on a form used as search criteria for a database query. The users have the option to save their searches so if they load one we need to pre populate all the search criteria they have saved. Most of the lists are simple look ups, we don't have codes and descriptions. For Regions we have AMER, EMEA, APAC as the value and the text of the drop downs. In this situation the "Contains" function will find the values in the list so we can mark them as selected.(Example 1) For users we store the user's Active Directory ID in the table. The users are use to seeing the names so in the ListBox for the query we have the value and the text as two separate values ("domain\kmcd" as the value, "Quaz" as the text). Here if we used "Contains" it will not find the items since we are not specifying the user's name in the New ListItem function. We don't store it in the database to conserve space and since the user ID is sufficient for the query there is no need. In this instance we found we can user the FindByValue and check for Is Nothing to determine if the value is in the drop down and select it prior to doing the search. (Example 2)
I'm not sure which function has more overhead but for now we've gotten around the problem and can use the FindByValue Is Nothing for future issues. At some point we may change the others to use FindByValue instead of Contains (60-70 dropdowns strewn all over the place.
Example 1
If Me.ddlKeyRegion.Items.Contains(New ListItem(key_regions(x))) Then
Me.ddlKeyRegion.Items.FindByValue(key_regions(x)).Selected = True
Example 2
If Me.ddlKeyUsers.Items.FindByValue(key_issued_by(x)) Is Nothing Then
Me.ddlKeyUsers.Items.FindByValue(key_issued_by(x)).Selected = True
No comments:
Post a Comment