我是VB.NET的新手,请原谅我这个愚蠢的问题。我有一个二维数组,想要用它的元素填充listview。为此,我正在尝试使用以下方法:
lst_arrayShow.Items.Clear()
For currentColumn As Integer = 0 To (columnsCnt - 1)
lst_arrayShow.Columns.Add("")
For currentRow As Integer = 0 To (rowsCnt - 1)
'lst_arrayShow.Items.Add()
Next
Next
我应该用什么代替'lst_arrayShow.Items.Add()
?
UPD: columnsCnt是数组中的列数,rowsCnt是数组中的行数
在多列中,ListView
您需要将属性设置View
为View.Details
,然后确保定义所有需要的列。因此,如果尚未在Designer中完成此操作,则需要将所需的列添加到ListView
lst_arrayShow.View = View.Details
For currentColumn As Integer = 0 To (columnsCnt - 1)
lst_arrayShow.Columns.Add("Column Nr: " & currentColumn
Next
接下来,既然您已经定义了列,则可以遍历行并ListViewItem
为每行创建一个。
在ListViewItem
具有Subitems
集合如上所定义的对应于列
For currentRow As Integer = 0 To (rowsCnt - 1)
' Create the listviewitem with the value from the first column
Dim item = new ListViewItem(yourArray(currentRow,0))
' The remainder columns after the first are added to the SubItems collection
For currentColumn As Integer = 1 To (columnsCnt - 1)
item.SubItems.Add(yourArray(currentRow,currentColumn))
Next
' Finally, the whole ListViewItem is added to the ListView
lst_arrayShow.Items.Add(item)
Next
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句