KB Article A1595
Visible to All Users

How can I allow end users to move the cursor within a grid cell via the arrow keys when its content is selected

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; } } }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.