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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multicolumn combo?

Status
Not open for further replies.

Mats

Technical User
Feb 18, 2000
83
EU
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.

Mats
 
Have you tried using a listview control?

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.

Hope this helps
 
Thanks for the code!

This could work in some cases, but in some i still need the combo-feel to the control.
 
Never mind, I finally figured it out.

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
order by [name])
 
To Mats :

The Microsoft From controls 2.0 Object library is not a standard VB Object Library.

What with the licenses of the OCX files if you distributed the controls ???

Eric
Eric De Decker
vbg.be@vbgroup.nl

Licence And Copy Protection AxtiveX.

Download Demo version on my Site:
Promotions before 02/28/2001 (free source codebook),visite my site
 
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
 
Thanks for the input!

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.

Mats
 
I cant remember where but I found it by entering <<multi column combo >> in some search engines. I think it was an activeX
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top