How do I put seperate data from a 2D array into different colums on a listbox? :confused:
Printable View
How do I put seperate data from a 2D array into different colums on a listbox? :confused:
Hi Steve,
Give this a try:
Just create a standard exe with a listview on it.Code:Option Explicit
Private Sub Form_Load()
'set the listview to report mode
ListView1.View = lvwReport
'just a test 2-dimensional array
Dim TempArray(2, 2) As String
TempArray(1, 1) = "TestData11"
TempArray(1, 2) = "TestData12"
TempArray(2, 1) = "TestData21"
TempArray(2, 2) = "TestData22"
'add the two column headers
ListView1.ColumnHeaders.Add , , "Data1"
ListView1.ColumnHeaders.Add , , "Data2"
'loop variable
Dim i As Integer
'listitem object
Dim LVItem As ListItem
For i = 1 To 2
'Add the first part of the array
Set LVItem = ListView1.ListItems.Add(, , TempArray(i, 1))
'Add the second part as a subitem
LVItem.SubItems(1) = TempArray(i, 2)
Next i
End Sub
You can change the code to fit your own needs.
Hope this helps
Shaun
That was even better than what I was looking for! Thanks! :D