Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // attach this to DataGridView1.CellContentClick event
- private void DataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
- {
- if (IsCurrentCellCheckBoxCell(sender)) {
- ((DataGridView)sender).EndEdit();
- PrintValueOfCurrentCheckBox();
- }
- }
- // result validation
- public void PrintValueOfCurrentCheckBox()
- {
- if (DataGridView1.CurrentCell == null)
- return;
- Console.WriteLine(DataGridView1.CurrentRow.Cells(DataGridView1.CurrentCell.ColumnIndex).Value.ToString());
- }
- // universal helper
- public static bool IsCurrentCellCheckBoxCell(object dataGridViewSender)
- {
- if (dataGridViewSender is DataGridView) {
- var _with1 = (DataGridView)dataGridViewSender;
- if (_with1.CurrentCell != null) {
- DataGridViewColumn currentColumn = _with1.Columns(_with1.CurrentCell.ColumnIndex);
- return currentColumn is DataGridViewCheckBoxColumn;
- }
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement