Datagridview的那个事件可以捕获到每行的绑定事件,就像web下girdview的datarowbingding事件一样。我希望实现隔行变色的效果。web的做过,winform这个控件不知道怎么实现,谢谢大家了。

解决方案 »

  1.   

     private void DgBase_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
            {
                for (int i = 0; i < DgBase.Rows.Count; i++)
                {
                    if (i % 2 == 0)
                    {
                        DgBase.Rows[i].DefaultCellStyle.BackColor = Color.Gainsboro; ;
                    }
                    else
                    {
                        DgBase.Rows[i].DefaultCellStyle.BackColor = Color.PowderBlue;
                    }            }
            }
      

  2.   

    用AlerternatingRowDefaultCellStyle属性
      

  3.   

    在dataGridView1的CellFormatting属性中添加。 private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
            {
                if (e.RowIndex %2== 0 ) 
                {
                    e.CellStyle.BackColor = Color.AliceBlue;
                }
            }
      

  4.   

    CSS
    /*DataGrid奇数行*/
    .EG_ItemCSS
    {
    background-color: #e5ecf1;
    }
    /*DataGrid偶数行*/
    .EG_AlternatingItemCSS
    {
    background-color: #d5e0e9;
    }