Hopefully an easy soltion to this (listbox question)

  • Thread starter Thread starter Brian Henry
  • Start date Start date
B

Brian Henry

I have a listbox, and i need to show a text string for selection, but each
item is tied to a number (not visible) i need to select the visible text and
have it return the number value, i know its possible with data sets and such
useing the display column and value column settings, but what if you arnt
useing a data set? how would i do this? thanks
 
Hi Brian,

Not as easy as you might think, at least I haven't found an easy way. One
solution: create a shadow array with both the string and the number as a
part of it. Then find the string in the array and you will get the
corresponding number. If, on the other hand, the string may be repeated,
you will have to use something like hashtables or any other key/value set
data type.

HTH,

Bernie Yaeger
 
found one myself :)

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"
 
* "Brian Henry said:
I have a listbox, and i need to show a text string for selection, but each
item is tied to a number (not visible) i need to select the visible text and
have it return the number value, i know its possible with data sets and such
useing the display column and value column settings, but what if you arnt
useing a data set? how would i do this? thanks

I remember I posted a solution to your previous thread. Have a look
there at all replies.
 
Back
Top