Check/Uncheck a checkbox on datagridview

前端 未结 16 737
野性不改
野性不改 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:44

    I use the CellMouseUp event. I check for the proper column

    if (e.ColumnIndex == datagridview.Columns["columncheckbox"].Index)
    

    I set the actual cell to a DataGridViewCheckBoxCell

    dgvChkBxCell = datagridview.Rows[e.RowIndex].Cells[e.ColumnIndex] as DataGridViewCheckBoxCell;
    

    Then check to see if it's checked using EditingCellFormattedValue

    if ((bool)dgvChkBxCell.EditingCellFormattedValue) { }
    

    You will have to check for keyboard entry using the KeyUp event and check the .value property and also check that the CurrentCell's column index matches the checkbox column. The method does not provide e.RowIndex or e.ColumnIndex.

提交回复
热议问题