KB Article A277
Visible to All Users

How to force the XtraGrid to auto-select cell contents

Description:
How do I force the grid to automatically select (highlight) all text in a cell when activated?

Answer:
`
Applies to: GridControl (ColumnView), TreeList
By default, the OptionsBehavior.AutoSelectAllInEditor option is activated and it makes the grid select text when a cell is opened for editing. However, when a cell is activated via a mouse click (vs. the Enter or F2 key), the click is redirected to the in-place editor and resets text selection. This behavior can be changed via the OptionsBehavior.EditorShowMode property. For example, please set it to MouseUp or Click.
In case with TreeList, enable the OptionsBehavior.ShowEditorOnMouseUp property.
If this is not suitable, you may want to try handling the GridView.ShownEditor event in the following manner:

C#
void gridView1_ShownEditor(object sender, EventArgs e) { GridView view = sender as GridView; BeginInvoke(new Action(()=> { view.ActiveEditor.SelectAll(); })); }
Show previous comments (3)
Andrew Ser (DevExpress Support) 11 years ago

    Hello,
    Since Stefan didn't show his solution, I suggest you use another one. Handle the GridView.ShownEditor event in the following manner:

    C#
    void gridView1_ShownEditor(object sender, EventArgs e) { BeginInvoke(new Action(()=> { gridView1.ActiveEditor.SelectAll(); })); }

    I hope you find this information useful and am looking forward to your results once you try this solution.

      Sorry about the wrong link, the solution I choose is adding a property SelectAllOnFocus documented here:
      http://www.devexpress.com/Support/Center/Question/Details/Q483398
      This way I don't have to handle ShownEditor in for each Grid I use (although, with a inherited Grid one could avoid this too…)

        Thank you Andrew and Stefan.
        I had actually forgotten about this topic, however the method I used was to handle the Click event of the repository text edit control.
                   repositoryItemTextEditFeature.Click += (sender, args) =>
                   {
                       var textEdit = sender as TextEdit;
                       if (textEdit != null) textEdit.SelectAll();
                   };

        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.