Listbox with key and text

  • Thread starter Thread starter Gilbert Tordeur
  • Start date Start date
G

Gilbert Tordeur

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.
 
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
 
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
 
* "Cor Ligthert said:
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...
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top