Color subitem的特定文字

时间:2017-08-29 07:33:19

标签: vb.net listview

我想使用字符串var属性检查子项的text属性,如果这些属性不匹配,请突出显示listview1.subitem

中的不匹配文本
  If founditem.SubItems(2).Text <> data then
   'highlight not equal text in lv1.subitem with yellow
  End if

有可能吗?我怎么能这样做?

1 个答案:

答案 0 :(得分:0)

将listview添加到您的项目并尝试此项

ListView1.Columns.Add("col1")
    ListView1.Columns.Add("col2")
    ListView1.Columns.Add("col3")
    ListView1.Columns.Add("col4")
    ListView1.Columns.Add("col5")
    Dim itms() As String = {"55", "55", "55", "55", "55"}
    For x As Integer = 0 To 4
        Dim lvi As New ListViewItem(itms(x))
        lvi.SubItems.Add(itms(x) & "-1")
        lvi.SubItems.Add(itms(x) & "-2")
        ListView1.Items.Add(lvi)
    Next
    itms = {"55", "55", "55", "55", "AA"}
    For x As Integer = 0 To 4
        Dim lvi As New ListViewItem(itms(x))
        lvi.SubItems.Add(itms(x) & "-1")
        lvi.SubItems.Add(itms(x) & "-2")
        ListView1.Items.Add(lvi)
    Next


    Dim control_str() As String = {"55", "55", "55", "55", "AA"}
    For Each itm As ListViewItem In ListView1.Items
        For i As Integer = 0 To itm.SubItems.Count - 1
            If itm.SubItems(i).Text <> control_str(i) Then
                itm.SubItems(i).BackColor = Color.Red
            End If
        Next


    Next