本文介绍了如何设置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.....
推荐答案
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行的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!