怎么样才能使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) 
 { 
 } 
 条件里内容不变就可以了= =!