我试图做的不是在列表视图中添加包含值的重复行,我试过了:
Private distinctResults As New Dictionary(Of String, String)()
'...
If Not (distinctResults.ContainsKey(GetTextId(columns))) Then
Dim item As ListViewItem = listViewShowLinks.Items.Add(id) '// ID.
item.SubItems.Add(subItemUrl) '// URL.
item.SubItems.Add(searchId) '// SEARCH ID.
item.SubItems.Add(pgex) '// PGEX.
item.SubItems.Add(ms) '// MS.
item.SubItems.Add(GetTextId(columns)) '// TEXT ID.
item.SubItems.Add(GetPrice(columns).Replace(",", ".")) '// PRICE.
item.SubItems.Add(GetTextId(columns)) '// TEXT ID.
item.SubItems.Add(GetPr(columns)) '// PR.
item.SubItems.Add(GetSr(columns)) '// SR.
listCopy.Add(item)
listViewShowLinks.EndUpdate()
End If
但它没有用,这个值:GetTextId(列)包含我要查找的密钥,输出就像
10123
10123
10124
10125
等
它确实是我不想添加的第一个值(行)。我不确定最好的方法。
任何帮助将不胜感激:)
欢呼人们格雷厄姆
答案 0 :(得分:-1)
这是一个更好的解决方案,代码行更少:
Dim distinctResults As New Dictionary(Of String, String)()
Dim isThere As Boolean = False 'This is used to check if the columns are there or is there
For Each vall In distinctResults.Values 'Sort all of the values inside of the Dictionary
If vall = GetTextId(columns) Then 'Check if it's found
isThere = True 'It's found, so set isThere to True
End If
Next
If isThere = False Then 'If it hasn't been set to found then do the following
Dim item As ListViewItem = listViewShowLinks.Items.Add(id) '// ID.
item.SubItems.Add(subItemUrl) '// URL.
item.SubItems.Add(searchId) '// SEARCH ID.
item.SubItems.Add(pgex) '// PGEX.
item.SubItems.Add(MS) '// MS.
item.SubItems.Add(GetTextId(columns)) '// TEXT ID.
item.SubItems.Add(GetPrice(columns).Replace(",", ".")) '// PRICE.
item.SubItems.Add(GetTextId(columns)) '// TEXT ID.
item.SubItems.Add(GetPr(columns)) '// PR.
item.SubItems.Add(GetSr(columns)) '// SR.
listCopy.Add(item)
listViewShowLinks.EndUpdate()
End If
我希望这是你需要的。