vb.net - How to avoid adding duplicate items in a Combobox in VB? -


i have combobox on form user select items in drop-down box, allowed enter own input. need user add items combobox without adding duplicate item displayed.

for example: combobox has list of dog breeds such (pug, boxer, pitbull). how not allow user enter "pug" when type combobox?

i'm coding in visual basic, thank you!!!!

i have tried it. works.

and assuming u want exception when duplicated value entered. following code , in combobox1.validating event.

private sub combobox1_validating(sender object, e system.componentmodel.canceleventargs) handles combobox1.validating         each item string in combobox1.items             if item.tolower.contains(combobox1.text.tolower)                 msgbox("duplicate value: there's '" & item & "' in list. please select list.", msgboxstyle.exclamation, "dog breed")                 combobox1.text = ""                 exit             end if         next     end sub 

for more information validating event, search yourself. thanks!


Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -