簡體   English   中英

VB.Net ListView

[英]VB.Net ListView

我正在嘗試使用ListView顯示數據集中的記錄。 在這些記錄中,我有4列:EmployeeID,EmployeeName,CustomerID和CustomerName。 雇員和客戶都有可能被多次列出,但使用不同的組合。

例如,如果我們有雇員1、2、3和客戶A,B,C,則我們可以有:(1A)(1B)(1C)(2A)(2B)等。

我的情況是我在listView中添加了(1A),然后嘗試添加(1B)時出現錯誤,提示它無法添加相同的項目。

到目前為止,這是我的代碼:

With list
     .Clear()
     .Columns.Add("Employee ID")
     .Columns.Add("Employee Name")
     .Columns.Add("Customer ID")
     .Columns.Add("Customer Name")
     For Each row As UpFromCostExceptions.dtExceptionsRow In _dsExceptions.dtExceptions
         Dim lvItem As ListViewItem = .Items.Add(row.EmpID.ToString)
         lvItem.SubItems.Add(row.EmployeeName)
         lvItem.SubItems.Add(row.CustomerID)
         lvItem.SubItems.Add(row.CustomerName)
     Next
     .Refresh()
End With

有人知道發生了什么嗎? 先謝謝您的幫助!

試試這個,我有一個簡單的類,有兩個字段,標識符,標題,我以這種方式填充列表。

'lstv = is the actual ListView Control
Dim i As Integer
Dim listitem As New ListViewItem
If lstv.Items.Count > 0 Then
    lstv.Items.Clear()
End If
For i = 0 To PropertyList.Count - 1
    listitem = New ListViewItem(PropertyList(i).Idefntifier)
    listitem.SubItems.Add(PropertyList(i).Title)        
    lstv.Items.Add(listitem)
Next i

我發現,如果我在創建ListItem並將其添加到ListView之前創建並添加子項,我可能會有重復的值。 這是我使用的代碼:

With listExceptions
            .Clear()
            .Columns.Add("Employee ID")
            .Columns.Add("Employee Name")
            .Columns.Add("Customer ID")
            .Columns.Add("Customer Name")
            For Each row As UpFromCostExceptions.dtExceptionsRow In _dsExceptions.dtExceptions
                Dim lvItem As New ListViewItem(row.EmpID.ToString)
                lvItem.SubItems.Add(row.EmployeeName)
                lvItem.SubItems.Add(row.CustomerID)
                lvItem.SubItems.Add(row.CustomerName)
                listExceptions.Items.Add(lvItem)
            Next
            .Refresh()
        End With

嘗試使row.EmpID.ToString()唯一,並查看它是否仍引發異常。

  Dim lvItem As ListViewItem = .Items.Add(row.EmpID.ToString)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM