473,464 Members | 1,476 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Listbox with key and text

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
4 926
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
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
* "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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Megan | last post by:
Hi- I'm creating a database of music bands with their cds and songs. I'm trying to program an SQL statement so that I can enter a string of text in a textbox, press the 'Enter' key, and have...
3
by: Ali Chambers | last post by:
Hi, I have created a listbox called "dtlist1" on my VB.NET form. I call a procedure as follows: Private Sub openfile(flname As String) dtlist1.Items.Clear() etc..
0
by: LostInMd | last post by:
Hi All, I've got an owner drawn listBox where I draw and measure the items that I add to the listBox. For example, I have a listBox that can only display 10 characters on each horizontal line. ...
1
by: Sunray | last post by:
I have a form called the sales form and i have 2 sets of listboxes So what happens is. i add items form the bottom set of list boxes which are bound to a data base to the top set of list boxes which...
5
by: Academia | last post by:
(If you've seen this in the drawing NG, sorry. I inadvertently sent it there.) I have a listbox populated with Objects. The Class has a String field that ToString returns. I assume that...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.