Discussion Locked

Multi column Combo box in VB V6.0

0 helpful
8 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
How do I create a Multi-column combo box using Microsoft Visual basic Version 6.0?

8 replies

by sl-campbell

As opposed to the MS Access DBCombo, the combo box delivered with VB6 does not automatically fill a list with more than one field. You have to do this manually.
What I do is get the fields from the recordset that I want to show in the combo and assign them to a variable. To do this you need to create a loop on the recordset in order to get the fields for all records:

Combo1.Clear

Do Until rsData.EOF

sListFld1 = rsData("myFirstField")
sListFld2 = rsData(("mySecondField")

Combo1.AddItem sListFld1 & vbTab & vbTab & sListFld2

rsData.MoveNext

Loop

However, you are dependent upon the vbTab to display "two" columns - you may have to change the Tab settings if it is too short or long (I believe 4 spaces in VB is default). You may just want to leave the default and add another vbTab.
Another way would be to use a list box in conjunction with a combo box - you can do more with a the values in a list box. When the user clicks on the combo, it doesn't open up butinstead the list box becomes visible. The combo box gets then updated based upon the selection in the listbox.

But the first way is the simplest and fastest way.

by sl-campbell

You can also do this by adding a reference to the MS Forms 2.0 Controls. One of the controls is a combo box that will allow multi-columns

by sl-campbell

You can also use the Microsoft Forms 2.0 in your project. You are not allowed to distribute it but I have found that most systems have it already, and it not, then the client can get the dll by loading IE 3+

Can this be closed now?

This discussion is closed to new replies.