如何防止在Devexpress中不添加新行时打开编辑表单

时间:2016-05-11 14:32:26

标签: vb.net gridview devexpress

我在Devexpress中有这个gridview。我有一个打开的弹出式编辑表单 当我想添加一个新行。但是,我想阻止弹出窗体 当我尝试编辑一行时打开。

我尝试过处理鼠标并双击事件,但我仍然得到了 一直弹出。

    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

2 个答案:

答案 0 :(得分:2)

虽然Abdellah提供的方法可能有效,但是当网格即将编辑数据时,不建议切换网格编辑模式。相反,网格为此提供专用事件。我建议您使用GridView.EditFormShowing事件来实现此目标。该事件提供了e.Allow和e.RowHandle,以防止显示编辑表单并识别当前行。

private void gridView1_EditFormShowing(object sender, DevExpress.XtraGrid.Views.Grid.EditFormShowingEventArgs e) {
    GridView view = (GridView)sender;
    e.Allow = view.IsNewItemRow(e.RowHandle);
}

答案 1 :(得分:1)

试试这个:

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
        e.Cancel = True
    End If
End Sub

或者是VB.Net中的Gosha_Fighten:

Private Sub GridView1_EditFormShowing(sender As Object, e As EditFormShowingEventArgs) Handles GridView1.EditFormShowing
    Dim view As GridView = TryCast(sender, GridView)
    e.Allow = view.IsNewItemRow(e.RowHandle)
End Sub