ComboBox - Items.Add command

Arg81

Well-known member
Joined
Mar 11, 2005
Messages
949
Location
Midlands, UK
Programming Experience
1-3
Hi Guys,

Hope someone can help :rolleyes:

I have a combobox which is I've put in items at design time.

I've set the combobox as a dropdown so that text can be added if the item isn't in the list.
What I want to do, is if the user types in something which isn't in the list, when the form is saved, it runs a command to save that text as a new item in the combobox.

I've tried;

If Not cboProductUsage.Items.Contains(cboProductUsage.Text) Then
cboProductUsage.Items.Add(cboProductUsage.Text)
End If

But that doesn't work, although there are no errors.
Has anyone done anything similar or got a solution for me to try?

Kind Regards,
Luke
 
Combobox

:p Hi Luke. Try to use the For Each loop thru the items of the combo, comparing combo's text with each item(n) in turn. Maybe place the code in the cbo's validating event

Good luck.
 
1) It probably is working....and working just like it should
2) It's not working like you think you expect it to.

I assume that you think it's not working because the next time you open the form, the information isn't there. Which is the way it is. In order for it to be there next time, you have to save the values somewhere (text file, xml file, database, *somewhere*) and when you reload the form, you then have to read those values from where ever you saved it, and add them to the combo box.

-tg
 
Back
Top