标题:请教LISTVIEW根据指定列内容数值更改当前行颜色,出错了
只看楼主
cpg4
Rank: 1
等 级:新手上路
帖 子:21
专家分:0
注 册:2009-5-3
结帖率:100%
已结贴  问题点数:20 回复次数:2 
请教LISTVIEW根据指定列内容数值更改当前行颜色,出错了
        For i As Integer = 0 To LvUser.Items.Count - 1
            Select Case LvUser.Items(i).SubItems(6).Text
                Case Is = 0
                    LvUser.Items(i).ForeColor = Color.Blue
                Case Is >= 1
                    LvUser.Items(i).ForeColor = Color.Green
            End Select
        Next
不能根据设置的颜色换色
搜索更多相关主题的帖子: 数值 LISTVIEW 颜色 
2009-09-03 23:46
limeng_HOHO
Rank: 2
来 自:上海
等 级:论坛游民
帖 子:49
专家分:50
注 册:2007-7-16
得分:0 
你的代码没问题 我试过了~ 肯定是其他地方出错了
我的测试代码:
Imports

Public Class Form1

    Private Sub writeToListView()
        Dim fs As FileStream = New FileStream("E:\fileName.txt", FileMode.Open)
        Dim sr As StreamReader = New StreamReader(fs)
        Dim str As String = sr.ReadLine()
        Dim substr(0, 2) As String
        substr(0, 0) = str.Substring(0, str.IndexOf(" ")) '3
        substr(0, 1) = str.Substring(str.IndexOf(" ") + 1, str.LastIndexOf(" ") - str.IndexOf(" ") - 1) '0
        substr(0, 2) = str.Substring(str.LastIndexOf(" ") + 1, str.Length - str.LastIndexOf(" ") - 1) '222
        ListView1.Items.Add(substr(0, 0))
        ListView1.Items.Add(substr(0, 1))
        ListView1.Items.Add(substr(0, 2))

        For i As Integer = 0 To ListView1.Items.Count - 1
            Select Case ListView1.Items(i).SubItems(0).Text
                Case Is = 0
                    ListView1.Items(i).ForeColor = Color.Blue
                Case Is >= 1
                    ListView1.Items(i).ForeColor = Color.Green
            End Select
        Next

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Call writeToListView()
    End Sub
End Class


世界并不美丽 然而又因此而美丽
2009-09-10 09:05
liuyilin
Rank: 2
等 级:论坛游民
帖 子:26
专家分:40
注 册:2007-3-8
得分:0 
回复 2楼 limeng_HOHO
你的代码出错了
2009-09-17 12:00



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-284724-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.326999 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved