My question is about.I have a datagridview in which i have fourth column as checkbox.
When clicking checkbox i want to get checkbox value in code behind. Can anybody help?
If you want the results when the checkbox value changes immediately, you'll need to implement a two step process.
First you'll need to generate the DataGridView's CurrentCellDirtyStateChange
event, Check if the DataGridView's CurrentCell is both not Nothing
and if the Index is 3 (since it is your fourth column), and finally commit the DataGridView.
Next you'll need to generate the DataGridView's CellContentClick
event. You'd need to check if the ColumnIndex
is 3 and if so then get the cell's value.
Here is an example:
Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
If e.RowIndex <> -1 AndAlso e.ColumnIndex = 3 Then
MessageBox.Show(DataGridView1.Rows.Item(e.RowIndex).Cells(e.ColumnIndex).Value.ToString)
End If
End Sub
Private Sub DataGridView1_CurrentCellDirtyStateChanged(sender As Object, e As EventArgs) Handles DataGridView1.CurrentCellDirtyStateChanged
If DataGridView1.CurrentCell IsNot Nothing AndAlso DataGridView1.CurrentCell.ColumnIndex = 3 Then
DataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit)
End If
End Sub
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.