Description:
How to Disable the Immediate Opening of In-Place Editors
Answer:
By default, the XtraGrid (and the XtraTreeList) opens the in-place editor immediately when clicked. For easier data browsing a user may prefer a behavior whereby a cell is not opened for editing at the first click. In other words, the first click should focus the clicked cell and then the second click on the same cell should open the editor.
It is easy to implement in the XtraGrid using the ShowingEditor event. You should store the current (focused) column and row in private fields and allow editing only if the editor is opened for a cell, which was already clicked (focused) previously.
C#DevExpress.XtraGrid.Columns.GridColumn prevColumn = null;
int prevRow = -1;
private void gridView1_ShowingEditor(object sender, System.ComponentModel.CancelEventArgs e)
{
DevExpress.XtraGrid.Views.Grid.GridView view;
view = sender as DevExpress.XtraGrid.Views.Grid.GridView;
if (prevColumn != view.FocusedColumn || prevRow != view.FocusedRowHandle)
e.Cancel = true;
prevColumn = view.FocusedColumn;
prevRow = view.FocusedRowHandle;
}
Visual BasicImports DevExpress.XtraGrid
Private prevColumn As Columns.GridColumn = Nothing
Private prevRow As Integer = -1
Private Sub GridView1_ShowingEditor(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles GridView1.ShowingEditor
Dim View As Views.Grid.GridView
View = CType(sender, Views.Grid.GridView)
If Not ((prevColumn Is View.FocusedColumn) And (prevRow = View.FocusedRowHandle)) Then
e.Cancel = True
End If
prevColumn = View.FocusedColumn
prevRow = View.FocusedRowHandle
End Sub
P.S. The described approach suits the XtraTreeList. The code should be slightly changed: the focused node must be stored instead of the grid row handle.
See Also:
How to make the grid activate its in-place editor on double click only