Home All Groups Group Topic Archive Search About

listbox displaymember & valuemember

Author
11 Jul 2006 1:53 AM
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

Author
11 Jul 2006 2:07 AM
tomb
Yes, your datasource must have at least two values, one to be displayed
and one to be the value.

T

Henry Jones wrote:

Show quoteHide quote
>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
>
>

>
Author
11 Jul 2006 2:41 AM
Henry Jones
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?


Show quoteHide quote
"tomb" <t***@technetcenter.com> wrote in message
news:OLDsg.87938$qd2.55506@bignews6.bellsouth.net...
> Yes, your datasource must have at least two values, one to be displayed
> and one to be the value.
>
> T
>
> Henry Jones wrote:
>
>>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
>>
>>
Author
11 Jul 2006 10:59 AM
Herfried K. Wagner [MVP]
Show quote Hide quote
"Henry Jones" <henryjo***@yada.com> schrieb:
>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>.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>