vb.net - 如何检查项目是否存在于另一个列表视图中?
问题描述
所以我有两个列表视图。我想检查 Listview1 中的项目 X 是否已存在于 ListView2 中,以及它是否改变了 ListView2 中项目的颜色。
For Each itm As ListViewItem In Form1.ListView1.Items
If itm.SubItems(0).Text.Contains(stringJoined) Then
itm.BackColor = Color.Red
End If
Next
解决方案
您可以使用第二个列表视图的Items.ContainsKey
方法:
For Each itm As ListViewItem In Form1.ListView1.Items
' Check for item is ListView2
If Form1.ListView2.Items.ContainsKey(itm.Key) Then
' Set BackColor to Red
Form1.ListView2.Items.Item(itm.Key).BackColor = Color.Red
End If
Next
这假设您使用键填充了两个列表视图,并且这两个项目将具有相同的键。
推荐阅读
- migration - 从 IdentityServer 2.4.0 迁移 -> IdentityServer4 4.1.2
- java - 读取文件时出现未知源错误
- sql - B树索引好像没有用?
- node.js - Webdriver.io (wdio) - Browserstack - waitforDisplayed 失败
- nltk - 使用 `nltk.parse.corenlp.CoreNLPParser` 时自定义标记器
- form-submit - 表单提交错误:激活链接在激活后一直发送
- javascript - 创建对象最安全的方法是什么(工厂、类、Eventmittler3)
- vue.js - Nuxt.js - 谷歌分析设置不跟踪任何活动
- javascript - Mapbox & D3:如何创建适当的颜色缩放?
- reactjs - 仅更改 State şin React 的一项属性