PDA

View Full Version : Solved: populate multicolumns of listview



white_flag
04-21-2010, 04:06 AM
hello

what is the most easy way to populate multiple columns in Listview from some ranges?
listviewcol. 1 listviewcol. 2 listviewcol. 3
range 1 range 2 range 3

and this is my code:


Private Sub UserForm_Initialize()
Dim i As Long
Dim LR As Long, LC As Long
Dim cell As Range

With Sheets("Sheet1")
LR = .Range("A" & .Rows.Count).End(xlUp).Row
LC = .Cells(1, .Columns.Count).End(xlToLeft).Column
End With

With ListView1
For Each cell In Range("A1", Cells(1, LC))
.ListItems.Add , , cell
ListView1_ItemClick .ListItems(.SelectedItem.Index) 'fill edit controls
Next cell
For Each cell In Range("A2", Cells(2, LC))

.ListSubItems.Add , , cell << error
ListView1_ItemClick .ListItems(.SelectedItem.Index) 'fill edit controls
Next cell

.ColumnHeaders.Add , , "Name", Me.TextBox1.Width 'Add columns
.ColumnHeaders.Add , , "Density", Me.TextBox2.Width
.HideColumnHeaders = False 'set some properties
.View = lvwReport
.Gridlines = True

End With
End Sub


thanx for the advice

fixo
04-21-2010, 06:15 AM
Try this one, it's working good on my end (Excel2007)



With Sheets("Sheet1")
LR = .Range("A" & .Rows.Count).End(xlUp).Row
LC = .Cells(1, .Columns.Count).End(xlToLeft).Column'<-- not used in this context
i = 1
With ListView1
For i = 1 To LR
Set cell = Cells(i, 1)
.ListItems.Add , , cell
.ListItems.Item(i).ListSubItems.Add , , cell.Offset(0, 1).Text
Next i

.ColumnHeaders.Add , , "Name", Me.TextBox1.Width 'Add columns
.ColumnHeaders.Add , , "Density", Me.TextBox2.Width
.HideColumnHeaders = False 'set some properties
.View = lvwReport
.Gridlines = True
.FullRowSelect = True
End With
End With


~'J'~

white_flag
04-21-2010, 06:50 AM
works good on Excel 2003 also. Many thanx

Antwan

fixo
04-21-2010, 08:59 AM
works good on Excel 2003 also. Many thanx

Antwan

Glad to help

Cheers :)

~'J'~