listbox displaymember & valuemember

  • Thread starter Thread starter Henry Jones
  • Start date Start date
H

Henry Jones

I want to populate a listbox with States but use abbreviations when someone
selects a state.

For instance if I have

California
Arizona
Nevada

in the listbox,

when the user clicks on "California", I would like to return the value "CA".
I did look at the properties Displaymember and Valuemember but they look
like they need to come from a datasource.

How can I accomplish this task?

Thanks
 
Yes, your datasource must have at least two values, one to be displayed
and one to be the value.

T
 
Yes, I know that there must be two values, but I was asking how to do what
I need to do in code to accomplish this with the few values that I have. Do
I need to put the values into a table or can I do something like

listbox1.items.add "California"
listbox1.items.add "Nevada" etc....

and if I can do this in code, how can I return "CA" when "California" is
clicked?
 
Henry Jones said:
I want to populate a listbox with States but use abbreviations when someone
selects a state.

For instance if I have

California
Arizona
Nevada

in the listbox,

when the user clicks on "California", I would like to return the value
"CA". I did look at the properties Displaymember and Valuemember but they
look like they need to come from a datasource.

Check out the code snippets in
<URL:http://dotnet.mvps.org/dotnet/code/controls/#ItemData>.
 
Back
Top