Reputation: 310
I have a DatagridView with data directly from a recordset.
I had a new column before the others as a checkbox type with this code:
Dim chk As New DataGridViewCheckBoxColumn()
gridRicette.Columns.Add(chk)
chk.HeaderText = "Sel."
chk.Name = "chk"
And it appear. But when I click on the the checkbox, nothing happens.
Can you help me to solve it?
Thanks!
Upvotes: 0
Views: 4752
Reputation: 1556
Try something like this....
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim chk As New DataGridViewCheckBoxColumn()
gridRicette.Columns.Add(chk)
chk.HeaderText = "Sel."
chk.Name = "chk"
End Sub
Private Sub gridRicette_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles gridRicette.CellContentClick
Dim senderGrid As DataGridView = sender
Dim data = senderGrid.Rows(e.RowIndex).DataBoundItem
If senderGrid.Columns(e.ColumnIndex).GetType() Is GetType(DataGridViewCheckBoxColumn) And e.RowIndex >= 0 Then
MessageBox.Show(String.Format("You selected row {0}", e.RowIndex))
End If
End Sub
End Class
You can use the DataGridView1_CellContentClick event and then determine what has been clicked by the user.... hope that helps.
Upvotes: 1