如何在选中复选框后更改datagridview中的行颜色

时间:2013-10-19 04:09:40

标签: c# datagridview

我想在我的行Chckbox处于选定模式后更改datagridview中特定行的颜色:

private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
    bool isSelect = dataGridView1[0, e.RowIndex].Value as bool? ?? false;
    if (isSelect)
    {
        // Change row color
    }
}

1 个答案:

答案 0 :(得分:2)

if (isSelect)
{
    // Change row color
    var row = this.dataGridView1.Rows[e.RowIndex]
    row.DefaultCellStyle.BackColor = Color.Red;
}