adgarcia13
asked on
Listbox bound to Data Control - how do I get 2 fields?
Greetings,
I have a listbox that binds to a data control which sources it's data from a table called RoadMap in an access database. As a result I currently get a list of "names" in the list when the program is run. What I would like to do is get the "name_id" (which is part of the same row in the database: name_id, name, third_field, and so on...) from the row/entry in the listbox that the user ultimately selects and populate a variable that will hold the selected "name_id".
The problem I am running into is that the listbox DataField property will only allow me to specify a single field to display in the listbox, so does that mean that is the only field available in the list? or is the data for the entire row in the table available? if it is, how do I get the "name_id" from the selected row? maybe I should be using some other approach?
Thanks Ahead,
Dave G.
hi adgarcia13
what u can do is...if name_Id fiedl (as is supposed to be) is an integer then in that case..
when u add name's into the listbox...give the index to that name as the name_id value..
which will make ur work easier and also searching etc. will be done easily..
for that do following..
do while not rs.EOF 'where rs is the recordset
List1.AddItem rs!Name, rs!name_Id
rs.movenext
loop
try this if it doesnot work for u then go for a bit cmplicated method ListView..
or another approach could be to add 2 listboxes..
one of which will store name_id and one its corresponding name for both the listindex would be the same in the 2 separate listboxes..
but as far as i know...the first method that i shown above...is much feasible and easy-to-use..
what u can do is...if name_Id fiedl (as is supposed to be) is an integer then in that case..
when u add name's into the listbox...give the index to that name as the name_id value..
which will make ur work easier and also searching etc. will be done easily..
for that do following..
do while not rs.EOF 'where rs is the recordset
List1.AddItem rs!Name, rs!name_Id
rs.movenext
loop
try this if it doesnot work for u then go for a bit cmplicated method ListView..
or another approach could be to add 2 listboxes..
one of which will store name_id and one its corresponding name for both the listindex would be the same in the 2 separate listboxes..
but as far as i know...the first method that i shown above...is much feasible and easy-to-use..
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can try for List view. This has much better control and you can view as many columns you desire.