Click here to Skip to main content
15,919,749 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,

I have a datagridview with a checkbox column. I want to capture the value of checkbox immediately when user changes it by clicking. I tried several events (CellValueChanged, CellClicked,CurrentCellDirtyStateChanged etc.) but nothing worked.

My code is

VB
Private Sub DataGridViewX3_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridViewX3.CellContentClick
      
If DataGridViewX3.Rows(DataGridViewX3.CurrentCell.RowIndex).Cells(8).Value = True Then
 DataGridViewX3.Rows(DataGridViewX3.CurrentCell.RowIndex).Selected = True
End If
Posted
Updated 1-Aug-12 4:38am
v3
Comments
Unareshraju 1-Aug-12 8:51am    
hi Khali,

try like this

private void checkBox1_Click(object sender, RoutedEventArgs e)
{
//u r displayed values
}

VB
Private Sub DataGridViewX3_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs)Handles DataGridViewX3.CellContentClick
       DataGridViewX3.CommitEdit(DataGridViewDataErrorContexts.Commit)
   End Sub
Private Sub DataGridViewX3_CellValueChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridViewX3.CellValueChanged
    '' do something with grid.Rows[e.RowIndex].Cells[e.ColumnIndex].Value 
End If
End Sub
 
Share this answer
 
v2
Comments
Member 11615133 12-Jun-15 1:28am    
thanks !!!, two days for find this solution.
Member 12028314 2-Oct-15 10:18am    
thank you! many days to search a solution!
Please check the below posts. They have accepted answers also.

1. Triggering a checkbox value changed event in DataGridView C#.NET[^].
2. Datagridview checkbox.checked event[^].
3. Capturing Checkbox click event in Windows Forms DataGridview[^].

Happy coding
Thanks...
 
Share this answer
 
v3
Comments
Thanks the asker for accepting...
And thanks to the person who upvoted....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900