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();
}));
}
Note: This fix comes with a disadvantage: Checkboxes don't get Checked/Unchecked using a single click and Popup-Editors (such as LookUpEditor) doesn't open automatically.
I fixed this issue the other way around: I let the EditorShowMode on Default, but changed the behaviour of the TextEditor Control. I used this sample to do this: http://www.devexpress.com/Support/Center/Question/Details/A277
Hello,
Thank you for sharing your ideas.
Feel free to contact us if you need any assistance.
Hmmm…Stefan's link points back to this topic. Does anyone know the alternative method he is referencing?
Hello,
Since Stefan didn't show his solution, I suggest you use another one. Handle the GridView.ShownEditor event in the following manner:
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();
};