Check/Uncheck a checkbox on datagridview

前端 未结 16 573
野性不改
野性不改 2020-11-30 11:19

Can someone help me why it doesn\'t work? I have a checkbox and if I click on it, this should uncheck all the checkbox inside the datagridview which were check

16条回答
  •  有刺的猬
    2020-11-30 11:47

    You can use this code on your grid CellClick event for check or unchecked cell checkbox :

    private void Grid_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 0)
            {
                Grid.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = (Grid.Rows[e.RowIndex].Cells[e.ColumnIndex].Value == null ? true : (!(bool)Grid.Rows[e.RowIndex].Cells[e.ColumnIndex].Value));
            }
        }
    

提交回复
热议问题