如何设置colorgridview行的颜色 [英] How set color to datagridview row

查看:118
本文介绍了如何设置colorgridview行的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



每个人



我想按颜色分组设置datagridview行。



喜欢



例如





1 abc

2 abc

3 abc

4 xyz

5 xyz

6 xyz

7 pqr

8 pqr

9 pqr

10 lmn

11 lmn

12 lmn



这里我想为行设置颜色

lik



abc =红色

xyz =蓝色

pqr =红色

lmn =蓝色



即我想将groupwise颜色设置为datagridview行。



请帮帮我...



谢谢...提前.....

Hi
Everyone

I want set group by color to datagridview rows.

like

eg


1 abc
2 abc
3 abc
4 xyz
5 xyz
6 xyz
7 pqr
8 pqr
9 pqr
10 lmn
11 lmn
12 lmn

Here i want to set color to the rows
lik

abc=red
xyz=blue
pqr=red
lmn=blue

i.e i want to set groupwise color to datagridview row.

Please help me...

Thanks ... In advance.....

推荐答案

可以使用项目数据绑定事件。对于网格绑定,在数据绑定事件你可以设置每一行的颜色。
can use item data bound event.On grid binding,in data bound event u can set the color of every row.


如何在gridview中设置行颜色。 [ ^ ]



我已经尝试过这个任务..还可以工作..我也可以尝试一下
how to set row colors in gridview.[^]

I already tried this task..and also work it..u can also try it


string tempStr = String.Empty;
private void dataGridView1_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
{
        if ((dataGridView1.Rows[e.RowIndex].Cells[1].Text) != tempStr)
        {
             dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Blue;
             tempStr = dataGridView1.Rows[e.RowIndex].Cells[1].Text;
        }
        else
        {
            dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Red;
        }
}







我没有测试过,可能有语法错误。




I did not test it, there may be syntax errors.


这篇关于如何设置colorgridview行的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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