By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,815 Members | 1,151 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,815 IT Pros & Developers. It's quick & easy.

Listbox with key and text

P: n/a
I would like to load a data table (2 fields : 1 numeric key and 1 text) into
a listbox, so that the listbox displays only the text but I could retrieve
the key associated to the element the user will select. How can I do ? Thank
you.
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Gilbert,

myListbox.datasource = mydatatable
myListbox.displaymember = "mytext"
myListbox.valudmember = "mykey"

And don't forget to protect the selectedIndexChange event with a switch
"switchListboxLoaded" with you set in the end of the load event to true,
because when the listbox is loaded from the table it fires and you will be
astonished why you got that error.

I hope this helps?

Cor
Nov 21 '05 #2

P: n/a
Easy

DataSource = YourTableName
DisplayMember = YourTableName.DisplayField
Valuemember = YourTableName.ValueField

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Gilbert Tordeur" <gi*************@fr.york.com> wrote in message
news:eP*************@TK2MSFTNGP09.phx.gbl...
I would like to load a data table (2 fields : 1 numeric key and 1 text) into a listbox, so that the listbox displays only the text but I could retrieve
the key associated to the element the user will select. How can I do ? Thank you.

Nov 21 '05 #3

P: n/a
* "Cor Ligthert" <no**********@planet.nl> scripsit:
myListbox.datasource = mydatatable
myListbox.displaymember = "mytext"
myListbox.valudmember = "mykey"


I would set the data source after setting display member and value
member.

Just my 2 Euro cents...

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #4

P: n/a
Herfried,

I did that that past, however stopped with that, did (as far as I remember
me) give one useless firing less however it fires. I find this setting the
datasource first nicer for the readability.

However just my 2 eurocents.

Cor

I would set the data source after setting display member and value
member.

Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.