x77 x77 - 1 year ago 155
Vb.net Question

DataGridView.Editmode = EditOnEnter. How to Select the row to Delete it?

When I use EditMode = EditOnEnter, The cell enter on editmode when I select the row.

It is hard to user to select the RowSelector to Delete the row.

do you know any Trick ?

x77 x77
Answer Source

I Try this Trick:

When Cell Click:

  • if index = -1 EndEdit and EditMode = DataGridViewEditMode.EditOnKeystrokeOrF2
  • Else If EditOnKeystrokeOrF2 - Restore EditMode and BeginEdit

Private Sub dgv2_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgv2.CellClick
    If e.ColumnIndex = -1 Then
       dgv2.EditMode = DataGridViewEditMode.EditOnKeystrokeOrF2
    ElseIf dgv2.EditMode <> DataGridViewEditMode.EditOnEnter Then
       dgv2.EditMode = DataGridViewEditMode.EditOnEnter
    End If
End Sub