Dynamically add Items to Combobox VB.NET -


i have 2 combobox in windows application. want programmatically add items second combobox based on selected in first combobox.

this in selected index change of combobox:

private sub combobox1_selectedindexchanged(sender object, e eventargs) handles combobox1.selectedindexchanged     try         if combobox1.selectedindex = 0             combobox2.items.add("mm")             combobox2.items.add("pp")         elseif combobox1.selectedindex = 1             combobox2.items.add("sms")         elseif combobox1.selectedindex = 2             combobox2.items.add("mms")             combobox2.items.add("ssss")         end if      catch ex exception      end try end sub 

it works fine, however, if keep selecting different items it's keep adding value on , over. add values once.

also, when add item prefer add id item description. tried:

combobox2.items.add("ssss", "1") 

it seems it's not working.

any suggestions?

try this

private sub combobox1_selectedindexchanged(byval sender object, byval e eventargs) handles combobox1.selectedindexchanged     try         if combobox1.selectedindex = 0             if not (combobox2.items.contains("mm")) , not (combobox2.items.contains("pp"))                 combobox2.items.add("mm")                 combobox2.items.add("pp")             end if         elseif combobox1.selectedindex = 1             if not (combobox2.items.contains("sms"))                 combobox2.items.add("sms")             end if         elseif combobox1.selectedindex = 2             if not (combobox2.items.contains("mms")) , not (combobox2.items.contains("ssss"))                 combobox2.items.add("mms")                 combobox2.items.add("ssss")             end if         end if      catch ex exception      end try 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -