• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 226
  • Last Modified:

What is the equivalent to the following ?


Hi,

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

Thanks,
Kishore
0
kishore_peddi
Asked:
kishore_peddi
1 Solution
 
S-TwilleyCommented:
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"
0
 
fceledonCommented:
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)
 me.key=key
 me.value=value
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)


fc:)


0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now