-
Hi.
I've problems about using listboxes. I dont know how to use multicolumn listboxes, how to add items etc.
In VB for Applications I was using :
List1.Additem ""
List1.list(1,0) ="Column1"
List2.list(1,1) ="Column1"
but it does not work in VB6.
Thanks in Advance.
-
Try using a listview control instead:
Code:
Private Sub Form_Load()
Dim objItem As ListItem
'set it so you can see the columns
ListView1.View = lvwReport
'create headers
ListView1.ColumnHeaders.Add , , "Product"
ListView1.ColumnHeaders.Add , , "Price"
'set first column data
Set objItem = ListView1.ListItems.Add(, "Phone", "Telephone")
'set second column data
objItem.SubItems(1) = "$50.00"
Set objItem = ListView1.ListItems.Add(, "Car", "Car")
objItem.SubItems(1) = "$58,500.00"
Set objItem = ListView1.ListItems.Add(, "book", "Tale of Two Cities")
objItem.SubItems(1) = "$15.00"
End Sub
Let me know if you need any further clarification.
-
...or..
'you could use tabs to give the illusion of columns
'set tab stops in a listbox
'appears as columns
'
Option Explicit
'
Public Declare Function SendMessageArray Lib _
"user32" Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Public Const LB_SETTABSTOPS = &H192
'<<<<< code for form >>>>>
'
Private Sub Command1_Click()
List1.AddItem "Nothing More"
List1.AddItem "Nothing Less"
List1.AddItem "Just A Sample"
Dim r As Long
'set up the tabstops in the listboxes
ReDim TabStop(1 To 3) As Long
'assign values to the tabs for the second third and fourth
'column (the first is flush against the listbox edge ie...0)
TabStop(1) = 80
TabStop(2) = 160
TabStop(3) = 240
'set the tabs
r = SendMessageArray(List1.hwnd, LB_SETTABSTOPS, 3, TabStop(1))
List1.Refresh
List1.AddItem "...A lesson" & vbTab & "in creating" & vbTab & "columns" & vbTab & "in a listbox!"
End Sub