通过单击c#(winform)更改datagridview单元格颜色

nam*_*mco 2 c# datagridview cell


我在表单上有一个数据网格.
我希望如此,
当我点击任何行上的任何单元格时
,单元格背面颜色可以更改为红色.
我怎样才能做到这一点...

Ume*_*AKA 7

使用单元格点击事件

在事件中只是将cell.backcolor分配给color.red

private void GridView_CellClick(object sender,DataGridViewCellEventArgs e)

    private void GridView_CellClick(object sender, DataGridViewCellEventArgs e){

        DataGridViewCellStyle CellStyle = new DataGridViewCellStyle();
        CellStyle.BackColor = Color.Red;
        dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Style = CellStyle;

    }
Run Code Online (Sandbox Code Playgroud)