读书人

如何样才能使dataGridView的前几行显示

发布时间: 2011-12-29 22:09:38 作者: rapoo

怎么样才能使dataGridView的前几行显示为红,下几行显示为绿,以此累推。
怎么样才能使dataGridView的前几行显示为红,下几行显示为绿,以此累推。

[解决办法]
private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
if (e.RowIndex > = 0 && e.RowIndex < 3)
{
e.CellStyle.BackColor = Color.Red;
}
else
{
e.CellStyle.BackColor = Color.Green;
}
}
前3行红,后面的绿
[解决办法]
private void coloring() {
int rnum;
for (rnum = 0; rnum < dataGridView1.Rows.Count; rnum++) {
if (rnum % 2 == 0) dataGridView1.Rows[rnum].DefaultCellStyle.BackColor = System.Drawing.Color.Chocolate;
else dataGridView1.Rows[rnum].DefaultCellStyle.BackColor = System.Drawing.Color.Gray ;
}
}
[解决办法]
UP
[解决办法]
2楼没有美学常识,红和绿相搭配,你的页面....
[解决办法]
股票行情么?
[解决办法]
private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
if (e.RowIndex /n==1) {
e.CellStyle.BackColor = Color.Red;
}
else if( e.RowIndex /n=0)

{
e.CellStyle.BackColor = Color.Green;
}
}

[解决办法]
五楼、六楼都是高人啊!
[解决办法]
只要把2楼那个变量在IF里的条件改成
if(rnum> =0 && rnum <3)
{
}
else if(rnum> =3 && rnum <6)
{
}
条件里内容不变就可以了= =!

读书人网 >C#

热点推荐