Eric Eric - 6 months ago 165
Vb.net Question

How to prevent edit form from opening when not adding a new row in Devexpress

I have this gridview in Devexpress. I have a pop-up edit form that opens up
when I want to add a new row. However, I would like to prevent the pop up form
to open when I try to edit a row.

I've tried handling the mouse down and double click events but I still get the
pop up all the time.

Private Sub gvMFFSeries_MouseDown(sender As Object, e As MouseEventArgs) Handles gvMFFSeries.MouseDown
Dim view As GridView = TryCast(sender, GridView)
Dim hitinfo = view.CalcHitInfo(e.Location)
If Not hitinfo.RowHandle = DevExpress.XtraGrid.GridControl.NewItemRowHandle Then
DXMouseEventArgs.GetMouseArgs(e).Handled = False
End If
End Sub

Private Sub gvMFFSeries_DoubleClick(sender As Object, e As EventArgs) Handles gvMFFSeries.DoubleClick
Dim view As GridView = TryCast(sender, GridView)
Dim mouseEventArgs As DXMouseEventArgs = TryCast(e, MouseEventArgs)
Dim hitinfo = view.CalcHitInfo(mouseEventArgs.Location)
If Not hitinfo.RowHandle = DevExpress.XtraGrid.GridControl.NewItemRowHandle Then
DXMouseEventArgs.GetMouseArgs(e).Handled = False
End If
End Sub


enter image description here

Answer

Try this :

Private Sub GridView1_ShowingEditor(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles GridView1.ShowingEditor
    Dim view As GridView = TryCast(sender, GridView)
    If view.IsNewItemRow(view.FocusedRowHandle) Then
        view.OptionsBehavior.EditingMode = GridEditingMode.EditForm
    Else
        view.OptionsBehavior.EditingMode = GridEditingMode.Default
    End If
End Sub