簡體   English   中英

如何防止在Devexpress中不添加新行時打開編輯表單

[英]How to prevent edit form from opening when not adding a new row in 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

在此輸入圖像描述

雖然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);
}

嘗試這個 :

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM