这就是我如何填充列表视图的方式。
With ListView1
.View = View.Details
.Columns.Add("Articles", "Articles")
.Columns.Add("Prix", "Prix")
.Columns.Add("Quantité", "Quantité")
.Columns.Add("Total", "Total")
End With
'populate "inputs"...
For Each item As Container In sList
Dim curEntry As New ListViewItem(New String() {item.sItemName.ToString(), item.sPrice.ToString("C2"), item.iNumber.ToString(), item.sPriceTot.ToString("C2")})
ListView1.Items.Add(curEntry)
Next我试着让subItem of selectedRow
ListView1.SelectedItems(0).SubItems("Articles").Text但是我得到了一个空异常,因为调用文本的subItem是空的,给我这个错误,但是为什么它是空的--它不应该是空的
我需要知道为什么是null,以及如何解决这个问题,谢谢。
发布于 2013-09-30 20:49:38
您可以依赖索引;示例代码(第一行和第一列):
Dim val11 As String = ListView1.SelectedItems(0).SubItems(0).Text或向行分配一个Name,并使用此名称来引用它:
Dim curEntry As New ListViewItem(New String() {item.sItemName.ToString(), item.sPrice.ToString("C2"), item.iNumber.ToString(), item.sPriceTot.ToString("C2")})
curEntry.Name = "Row 1"
ListView1.Items.Add(curEntry)
Dim val11 As String = ListView1.Items("Row 1").SubItems(0).Text更新:
如果您通过自己的方法( SubItems ) (SubItems.Add)添加它们并为它们分配一个Name,您也可以通过其Name引用它们(列):
Dim curEntry As New ListViewItem(New String() {item.sItemName.ToString(), item.sPrice.ToString("C2"), item.iNumber.ToString(), item.sPriceTot.ToString("C2")})
curEntry.SubItems.Add("otherColumn").Name = "5th column"
curEntry.Name = "Row 1"
ListView1.Items.Add(curEntry)
Dim val15 As String = ListView1.Items("Row 1").SubItems("5th column").Texthttps://stackoverflow.com/questions/19103204
复制相似问题