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.
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.
Chris
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.