Advertisement
Guest User

http://stackoverflow.com/q/32424

a guest
Sep 6th, 2015
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.88 KB | None | 0 0
  1. // attach this to DataGridView1.CellContentClick event
  2. private void DataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
  3. {
  4.     if (IsCurrentCellCheckBoxCell(sender)) {
  5.         ((DataGridView)sender).EndEdit();
  6.         PrintValueOfCurrentCheckBox();
  7.     }
  8. }
  9.  
  10. // result validation
  11. public void PrintValueOfCurrentCheckBox()
  12. {
  13.     if (DataGridView1.CurrentCell == null)
  14.         return;
  15.     Console.WriteLine(DataGridView1.CurrentRow.Cells(DataGridView1.CurrentCell.ColumnIndex).Value.ToString());
  16. }
  17.  
  18. // universal helper
  19. public static bool IsCurrentCellCheckBoxCell(object dataGridViewSender)
  20. {
  21.     if (dataGridViewSender is DataGridView) {
  22.         var _with1 = (DataGridView)dataGridViewSender;
  23.         if (_with1.CurrentCell != null) {
  24.             DataGridViewColumn currentColumn = _with1.Columns(_with1.CurrentCell.ColumnIndex);
  25.             return currentColumn is DataGridViewCheckBoxColumn;
  26.         }
  27.     }
  28.     return false;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement