Populating a ListView

2019-08-25 04:24发布

I am struggling populating a listview, I have never used them before.

I can populate one column, but I am struggling to populate the next column.

This is what I have:

With ListView1
   .View = lvwReport
   .FullRowSelect = True
   .Gridlines = True
   With .ColumnHeaders
      .Clear
      .Add , , "Language", 70
      .Add , , "Language", 70
      .Add , , "Language", 70
   End With

End With




    Set sh = ThisWorkbook.Worksheets(4)
    With sh
        LR = .Range("A" & .Rows.Count).End(xlUp).row
    End With
    lC = 0


For r = 2 To LR
Set li = ListView1.ListItems.Add
   li.ListSubItems.Add , , sh.Cells(r, 4).Value
Next

I thought I could just add an extra

Set li = ListView1.ListItems.Add
   li.ListSubItems.Add , , sh.Cells(r, 5).Value

But this just appends the first column.

Thanks

标签: excel vba
1条回答
Viruses.
2楼-- · 2019-08-25 05:00

I think you need to use:

Set li = ListView1.ListItems.Add(, , "Item 1")

And then move on with your ListSubItems. Have a look here and scroll down. Some nice examples.

查看更多
登录 后发表回答