rickyoswald
Programmer
I have been trying to make a multi-column list box which will fill with data from a database. The default listbox control in VB6 only has one column, is there property or a similar control that I can use?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Option Explicit
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Private Sub Command1_Click()
End
End Sub
' Multicolumn listbox or combo
' Courier font is used because it has an equal character width
' unlike other fonts
Private Sub Form_Load()
Dim x As Integer
Dim y As Integer
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
cn.Provider = "Microsoft.Jet.OLEDB.4.0"
cn.ConnectionString = App.Path & "\sample.mdb"
cn.Open
rs.Source = "select * from suppliers"
rs.Open , cn, adOpenKeyset, adLockOptimistic
Do Until rs.EOF
x = Len(Left(rs!CompanyName, 38))
x = 38 - x
y = Len(Left(rs!ContactName, 20))
y = 22 - y
List1.AddItem rs!CompanyName & Space(x) & Space(2) & Left(rs!ContactName, 20) & Space(y) & rs!contacttitle
rs.MoveNext
Loop
rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing
End Sub
Form1.lstVw1.ListItems.Add 1, , "This"
Form1.lstVw1.ListItems(1).SubItems(1) = "is"
Form1.lstVw1.ListItems(1).SubItems(2) = "adding"
Form1.lstVw1.ListItems(1).SubItems(3) = "items"