我想在listview中添加一个字符串数组,我可以用
添加一个数组ListView1.Items.AddRange(string1 .Select(Function(x) New ListViewItem(x)) _
.ToArray)
但如何在第二列中添加第二个subitem
使他们面对面
我也试过
For Each s As String In string1
Dim item As New ListViewItem
livv.Items.Add(t)
ListView1.Items.Add(item)
For Each t As String In string2
Dim item2 As New ListViewItem
item2.SubItems.Add(t)
ListView1.Items.Add(item2)
Next
next
但它不起作用。如何将两个字符串数组添加到listview中?
答案 0 :(得分:1)
假设数组大小相同,可以使用For n Loop:
Dim lvi As ListViewItem
For n As Int32 = 0 To string1.Length - 1
' create new LVI with data from string1
lvi = New ListViewItem(string1(n))
' add corresponding string2 element as the only subitem
lvi.SubItems.Add(string2(n))
' add LVI to listview
myLV.Items.Add(lvi)
Next
如果没有相同数量的元素,则必须添加测试并做出相应的响应。