private
void
dataGridView1_DataBindingComplete(
object
sender, DataGridViewBindingCompleteEventArgs e)
{
if ( this .dataGridView1.Rows.Count != 0 )
{
for ( int i = 0 ; i < this .dataGridView1.Rows.Count; )
{
this .dataGridView1.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.Pink;
i += 2 ;
}
}
}
如果没有绑定数据库,那么当dataGridView中的数据有所改变或显示的时候可以添加以下的代码:
{
if ( this .dataGridView1.Rows.Count != 0 )
{
for ( int i = 0 ; i < this .dataGridView1.Rows.Count; )
{
this .dataGridView1.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.Pink;
i += 2 ;
}
}
}
if
(
this
.dataGridView1.Rows.Count
!=
0
)
{
for ( int i = 0 ; i < this .dataGridView1.Rows.Count; )
{
this .dataGridView1.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.Pink;
i += 2 ;
}
}
{
for ( int i = 0 ; i < this .dataGridView1.Rows.Count; )
{
this .dataGridView1.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.Pink;
i += 2 ;
}
}