DataGridView changing cell background color

后端 未结 10 1692
没有蜡笔的小新
没有蜡笔的小新 2020-11-30 10:20

I have the following code :

private void dgvStatus_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
    foreach (DataGridViewRow          


        
10条回答
  •  天涯浪人
    2020-11-30 10:36

    try the following (in RowDataBound method of GridView):

    protected void GridViewUsers_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        // this will only change the rows backgound not the column header 
    
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[0].BackColor = System.Drawing.Color.LightCyan; //first col
            e.Row.Cells[1].BackColor = System.Drawing.Color.Black; // second col
        }
    }
    

提交回复
热议问题