I've got a DataGridView
including a DataGridViewButtonColumn
. The user should be able to use the button directly so I set EditMode
to EditOnEnter
. But, the first click didn't fire the Click
event - It seems like the first click selects/focus the row/column?
So I tried to use the CellClick
Event:
Private Sub dgv_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgv.CellClick
Dim validClick = (e.RowIndex <> -1 And e.ColumnIndex <> -1)
If (TypeOf dgv.Columns(e.ColumnIndex) Is DataGridViewButtonColumn And validClick) Then
dgv.BeginEdit(True)
CType(dgv.EditingControl, Button).PerformClick()
End If
End Sub
But this solution didn't work either. EditingControl
always throws a NullReferenceException
.
Any ideas?