How do I create a multicolumn combobox? I would like to create a combo with two columns, one visible and one hidden. In MS Access this was very simple, but in VB I just cant figure it out. I am retreiving the records from a database.
I'm doing something similar using code attached. You need a listview control with view property set to report. This segment runs from a button called cmdAll.
Private Sub cmdAll_Click()
Dim cnn1 As ADODB.Connection
'***mydata is a public string set to the full filename of the .mdb database
Dim mySQL As String
Dim rst As Recordset
mySQL = "SELECT name, calltime, problemtext FROM tblCalls "
Set cnn1 = New ADODB.Connection
With cnn1
.Provider = "Microsoft.Jet.OLEDB.3.51"
.Open myData
End With
count1 = 1
Set rst = New Recordset
With rst
Set .ActiveConnection = cnn1
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open mySQL
Do While Not .EOF
Set itmx = Lvw1.ListItems.Add(count1, , !name)
itmx.SubItems(1) = !calltime
itmx.SubItems(2) = !problemtext
.MoveNext
count1 = count1 + 1
Loop
rst.Close
Set rst = Nothing
End With
If count1 = 1 Then
MsgBox "No items"
End If
End Sub
You can set the column widths in the listview control so that any column is not shown.
Using the combo from Microsoft From controls 2.0 it works. Columncount=2 and Bound Column=2, rst is my recordset.
With this code I see rst(1) and rst(0) is the value of the combo. The recordset must be sorted, because automatic soprting wont work (you'll get strange results...)
Dim i As Integer
i = 0
Do Until rst.EOF
ComboBox1.AddItem rst(1), i
ComboBox1.Column(1, i) = rst(0)
rst.MoveNext
i = i + 1
Loop
To get sorted lists for combos, you can base the combo data on a sorted query in the access MDB database or on a sql statement that is the same as the sql code for the query.
eg.(select * from
Re licences: I paid for the version 2.0 with the original Vb4 or (maybe C++ I think)along with some Sheridan 3D controls and they have stayed in my computer ever since as I updated. They work OK with VB6 so I can't see why you cant distribute them legally OK
Do you know of any problems?
Anyway you should be able to do the same with the later combo because you'd be getting the data from a recordset and not the combo box.
There are some third party multi combo thingys around on the internet if you want to show more than one column like in Access and you could make one colum zero width.
Ted
I haven't really thought about the licenses, I think the MS Forms 2.0 controls came with Visual Studio Enterprise Edition 6.0 and should therefore be free to distribute. Perhaps I should check...
tedsmith:
Could you point me to some third party multicolumn combos on the net? I would like to check them out.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.