如何根据项目值更改listview项目的单元格(背面或前面颜色)的颜色 [英] How to change the color of a cell(back or fore color) of listview item according to item value

查看:97
本文介绍了如何根据项目值更改listview项目的单元格(背面或前面颜色)的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用if条件根据项目值更改listview项目的单元格(背面或前面颜色)的颜色。



我这样做但它是不工作并且没有显示错误

请帮助我......



我尝试过:



How to change the color of a cell(back or fore color) of listview item according to item value with if condition.

I do it but it is not work and show no error
Please help me......

What I have tried:

Private Sub btnaddcat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnaddcat.Click
        For k = 0 To ListView1.Items.Count - 1
            If ListView1.Items(k).SubItems(6).Text > 10000 Then
                ListView1.Items(k).SubItems(6).ForeColor = System.Drawing.Color.Red
            End If
        Next k
    End Sub

推荐答案

您无法按照您尝试的方式比较字符串和整数值。

一种可能的解决方案是在比较之前将字符串值解析为整数:

You cannot compare a string and an integer value the way you tried to.
One possible solution could be to parse the string value to an integer before the comparison:
Dim value As Integer
If Integer.TryParse(ListView1.Items(k).SubItems(6).Text, value) Then
   If value > 10000 Then
      '' ...
   End If
End If


这篇关于如何根据项目值更改listview项目的单元格(背面或前面颜色)的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆