在Vb.net中如何为Listview的特定单元格赋予不同的颜色 [英] In Vb.netHow to give different colors to particular cell of a Listview

查看:469
本文介绍了在Vb.net中如何为Listview的特定单元格赋予不同的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我创建了一个列表视图,并将项目和子项目绑定到该列表视图.
我想要的就是给特定列的特定行赋予颜色.

我已经尝试过了,

Hi all,

I have created a listview and binded items and subitems to it.
All i wanted is give colors to particular rows of particular column .

I have tried like this,

Dim strSQLReport As String = "Select * from Buzz;
Dim cmdReport As New SqlClient.SqlCommand(strSQLReport, con)
Dim readerReport As SqlClient.SqlDataReader = cmdReport.ExecuteReader()
Dim l As Integer = 0, m As Integer
m = ListViewReport.Items.Count
If readerReport.HasRows Then
    While readerReport.Read()
        m = l + 1
        ListViewReport.Items.Add(m)
        ListViewReport.Items(l).SubItems.Add(readerReport(3))
        ListViewReport.Items(l).SubItems.Add(readerReport(4))

         
<big>        If readerReport(6) = "Success..." Then
            ListViewReport.Items(l).SubItems.Add(readerReport(6))
            ListViewReport.Items(l).SubItems(0).ForeColor = Color.Green
        Else
            ListViewReport.Items(l).SubItems.Add(readerReport(6))
            ListViewReport.Items(l).SubItems(0).ForeColor = Color.Red
        End If
</big>        

        'ListViewReport.Items(l).SubItems.Add(readerReport(6))
        'ListViewReport.Items(l).SubItems.Add( 
        '    Format(
        '     Format(readerReport.GetSqlDateTime(5).Value.ToShortDateString())))
        ListViewReport.Items(l).SubItems.Add(Format(Format(readerReport.GetSqlDateTime(5).Value.ToString("dd/MM/yyyy"))))
        ListViewReport.Items(l).SubItems.Add(Format(readerReport.GetSqlDateTime(5).Value.ToLongTimeString()))
        ListViewReport.Items(l).SubItems.Add(readerReport(1))

        l = l + 1
    End While
End If



希望很快能听到

在此先感谢

问候

Naveen .....



Hope to hear soon

Thank in advance

Regards

Naveen.....

推荐答案

首先,我将使用for循环而不是while循环,因为for循环将维护您的计数器.

其次,您似乎要设置商品的颜色-而不是子商品.

您根本没有得到任何颜色,还是错误的单元格正在改变颜色?
First, I would use a for loop instead of a while loop because the for loop will maintain your counter.

Second, it looks like you want to set the Item''s color - not the sub-items.

Are you not getting any color at all, or is it that the wrong cell is changing color?


谢谢约翰·西蒙斯

在我的代码中,我无法为此提供原色
在绿色中具有成功..."且在红色中具有失败"的特定单元格,均在同一列中.

约翰·西蒙斯先生,我该怎么办.

在此先感谢

问候

Naveen ...
Thank u John Simmons

Here in my code ,im not able to give forecolor for that
particular cell which has "Success..." in GREEN COLORand other one is "Failed" in RED COLOR ,Both in same column.

How will i do it Mr.John Simmons.

Thanks in advance

Regards

Naveen...


这篇关于在Vb.net中如何为Listview的特定单元格赋予不同的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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