Is there any way how to select all text in ComboBoxTool by a single click? I am looking for something like SelectAll() for ComboBox.
Thanks, Maksim.
Great! Let me know if you have any further questions.
Chris
Handling of the AfterToolEnterEditMode event works. That is exactly what I want. Thank you!
Hello Maksim,
BeforeToolEnterEditMode may be too early to specify the selection since it is not fully in edit mode yet. Setting the SelectionStart and SelectionLength appear to work fine in the AfterToolEnterEditMode event handler.
Note that this will not cause text to be selected on every click; it will only select the text when it goes into edit mode. Clicking on the editor once when it is already in edit mode will still give the user the ability to reposition the caret. If you still want it to occur on every click, that will be a bit more difficult, as you'll have to find the EmbeddableTextBox in the Controls collection of the owning UltraToolbarsDockArea, and hook up to it's Click event.
Chris,
The question was "How to select text by a single click" :)
Unfortunately, your sample doesn't work for me. I am trying to set SelectionStart and SelectionLenth in a handler of the BeforeToolEnterEditMode event. The value of the SelectionLength property stays 0 after setting any another value.
The ComboxBoxTool does not have a SelectAll() method, but you can achieve the same functionality by using the SelectStart and SelectionLength properties. By setting the SelectionStart to 0 and the SelectionLength to the length of the tool's Text, you can achieve the same behavior as SelectAll().
Additionally, you could simply set the SelectedText property to the value of the Text property.
There are two requirements to text selection. First, the tool must be in edit-mode. This can be accomplished by setting the IsInEditMode property to true. Second, the tool must support text selection which is handled by the DropDownStyle property. The default DropDownStyle is DropDownList which does not support text editing/selection. Change the DropDownStyle property to DropDown to allow both text editing and selection. Here is a quick code snippet that will select all the text in ComboxTool1 when a button on the form is clicked:
private void button1_Click(object sender, EventArgs e) { ComboBoxTool tool = this.ultraToolbarsManager1.Toolbars[0].Tools["ComboBoxTool1"] as ComboBoxTool; if (tool.DropDownStyle == Infragistics.Win.DropDownStyle.DropDown) { tool.IsInEditMode = true; tool.SelectedText = tool.Text; // Or... //tool.SelectionStart = 0; //tool.SelectionLength = tool.Text.Length; } }
private void button1_Click(object sender, EventArgs e)
{
ComboBoxTool tool = this.ultraToolbarsManager1.Toolbars[0].Tools["ComboBoxTool1"] as ComboBoxTool;
if (tool.DropDownStyle == Infragistics.Win.DropDownStyle.DropDown)
tool.IsInEditMode = true;
tool.SelectedText = tool.Text;
// Or...
//tool.SelectionStart = 0;
//tool.SelectionLength = tool.Text.Length;
}
Let me know if you have any questions.