Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to make a combo or list boxes showing two colunms?

Status
Not open for further replies.

Gunga

IS-IT--Management
Oct 8, 2002
8
0
0
BR
Hello folks,

I need to use a combo and a list boxes showing two colunms but only picking the data from the one colunm to be stored.

The other option is to show just one colunm but data to be stored is one behind.

For example:

Table Products: Id Description
1 banana
2 orange
3 passion fruit
4 apple


I want to store data from the Id colum and displaying for the user the Description colunm, or both.
 
The Forms 2.0 Combo Box supports multiple columns Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
The conventional way to handle a description/id pair is to display the descriptions ("banana", "orange", etc), and to store the IDs in the control's ItemData array, like so:

Combo1.AddItem "orange"
Combo1.ItemData(Combo1.NewItem) = 1

Then you can retrieve the id with:
lngSelectedID = Combo1.ItemData(Combo1.SelectedItem)
(This is from memory, so the SelectedItem property might actually be called something else...)

Alternatively, if you want to display both pieces of data, you can concatenate them into a string, and you can even align the second piece of data by adding a tabstop to the control using the SetTabStops (I think) Windows message.

gkrogers
 
Corrections:

i) it's not "NewItem", it's "NewIndex";

ii) it's not "SelectedItem", it's "ListIndex". Although, note that while this will always work with a combobox, it will only work correctly with a single-select listbox (i.e. the MultiSelect property must be set to 0). For multi-select listboxes you have to iterate through the Selected array, referencing the corresponding ItemData value. gkrogers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top