x77 x77 - 6 months ago 68
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

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
       dgv2.EndEdit()
    ElseIf dgv2.EditMode <> DataGridViewEditMode.EditOnEnter Then
       dgv2.EditMode = DataGridViewEditMode.EditOnEnter
       dgv2.BeginEdit(False)
    End If
End Sub