我有一个包含4列且接近1500行的ListView。我想知道如何将它传递给数组。我希望ListView中的行和列匹配数组中的维度。
position '3'
答案 0 :(得分:0)
试试这个:
Dim allItems(ListView1.Items.Count-1) As ListViewItem
ListView1.Items.CopyTo(allItems, 0)
' To iterate
For Each r In allitems
' Row is r.index
For Each c In r.SubItems
' Text in each column is c.Text
Next
Next
答案 1 :(得分:-1)
鉴于数据已经在ListView
中,您可以执行以下操作:
Dim matrix(ListView1.Items.Count - 1, 3)
For r As Integer = 0 To ListView1.Items.Count - 1
Dim itemX = ListView1.Items(r)
matrix(r, 0) = itemX.Text
matrix(r, 1) = itemX.SubItems(0).Text
matrix(r, 2) = itemX.SubItems(1).Text
matrix(r, 3) = itemX.SubItems(2).Text
Next
所以这就是你通过动态引用列来实现的 - Subitem
s:
Dim matrix(ListView1.Items.Count - 1, 3)
For r As Integer = 0 To ListView1.Items.Count - 1
Dim itemX = ListView1.Items(r)
matrix(r, 0) = itemX.Text ' The first item in the array
For c As integer = 1 To itemX.Subitems.Count
matrix(r, c) = itemX.Subitem(c - 1).Text
Next
Next