ColinYamauchi
asked on
Trap or create a not in list event for a combo box
The Microsoft Access combo box has a not in list event that enables the developer to trap the event and ask the user if he wants to add it to the list. Is there a way to do this using vb.net 2005 by raising my own not in list event?
ASKER
Thanks much for your answer. Do you know if I could do the same thing if I populated the combo box from a database using a data reader?
How do you fill the combobox ? What datasource you have ?
Show some code!
Show some code!
ASKER
In our shop we store objects that contain the combo box display member and value member as properties. So I will use the Leave event as you suggested, but I will loop through the combo box items collection to see if the item exists. If it does'nt exist I will call sub new for the object and load the new value into the object property and add the new object as a new item for the combo box. I am not sure if this will take too long because searching for the item will require that I convert the item back into the object and then check its property to see if it matches what the user types into the combo box. Thanks for your help. I have attached a sample code to show how the object is loaded (each as a new instance into the combo box.
LoadComboBox.txt
LoadComboBox.txt
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I will keep your new code for future use. In the meantime, I dislike loading combo boxes with datasets, because when I try to open the form with blank fields to add a new record, the combo box loads with the top item on the list, even though it should be blank. Changing the selected index to -1 does not help. I can still and will rewrite the code to load the box with objects and check if the item exists and if not then add a new object instance. Thanks for your help
Check this example I have post it (that also allows you to insert it)
https://www.experts-exchange.com/questions/23760668/Dropdown-Combo-save-entered-text-not-in-list-in-VB-Net.html