Description:
I want end users to be able to use the LEFT and RIGHT arrow keys to deselect a cell's content when editing starts.
Answer:
When the view's OptionsBehavior.AutoSelectAllInEditor property is set to true, XtraGrid emulates MS Access's behavior. When an end user starts editing, the cell's content is automatically selected. In this case pressing the LEFT or RIGHT arrow key focuses the neighboring cell but does not deselect the cell's content. If you want to deselect the text in such cases, you should handle the grid's EditorKeyDown event as in the example below:
C#private void gridControl1_EditorKeyDown(object sender, System.Windows.Forms.KeyEventArgs e) {
DevExpress.XtraGrid.Views.Base.BaseView view = gridControl1.KeyboardFocusView;
if((e.KeyCode == Keys.Left || e.KeyCode == Keys.Right) && view.ActiveEditor != null) {
DevExpress.XtraEditors.TextEdit te = view.ActiveEditor as DevExpress.XtraEditors.TextEdit;
if(te != null && te.Text != null && te.SelectionLength == te.Text.Length) {
view.ActiveEditor.DeselectAll();
e.Handled = true;
}
}
}