What is the equivalent to the following ?


In the Web applications, we have

DropDownList1.Items.Add(New ListItem("Kishore","20")) //Key - value

What is the equivalent in Windows applications for combo box ?

ComboBox1.Items.Add(---------------------------------)  //Want for Key-Value

Who is Participating?
I don't know too much about Key properties in combobox... but I think this is probably the nearest to it...

An example: (pulled from the help file)
Dim USStates As New ArrayList()

USStates.Add(New USState("Washington", "WA"))
USStates.Add(New USState("West Virginia", "WV"))
USStates.Add(New USState("Wisconsin", "WI"))
USStates.Add(New USState("Wyoming", "WY"))

ListBox1.DataSource = USStates
ListBox1.DisplayMember = "LongName"
ListBox1.ValueMember = "ShortName"
There is no direct equivalent to the key/value in the ComboBox, however, combobox displays whatever you have in the object's item ".ToString" value:

private class cbItem
public [Key] as string
Public [Value] as string
public sub New([Key] as string,[Value] as string)
end sub
public overrides function tostring() as string
return Value
end sub
end class

ComboBox1.items.add(new cbItem("Key","Value")
or also
ListBox1.items.add(new cbItem("Key","Value")

later, recover with:
dim cb as cbItem=ctye( combobox1.selecteditem,cbItem)


Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.