This is a migrated thread and some comments may be shown as answers.

Open, Focus and SelectAllText

2 Answers 220 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Patrik
Top achievements
Rank 1
Patrik asked on 15 May 2013, 11:46 AM
Hi everyone,

I would like to open, focus and select all text in editable RadComboBox when my wpf form is opened.

So I set following properties:

OpenDropDownOnFocus="True" SelectAllTextEvent="GotFocus"

and I call the Focus(); on form's constructor.

But the comboBox is closed with no selected text in it.

Could you help me what am I doing wrong?

Thank you for your replies.

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 16 May 2013, 05:41 AM
Hi Patrik,

Please have a look at the following code I tried which works fine at my end.

C#:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
    radComboBox.OpenDropDownOnFocus = true;
    radComboBox.Focus();
    //set the selected index value as the index of the desired item.
    radComboBox.SelectedIndex = 3;
}

Thanks,
Shinu.
0
Vladi
Telerik team
answered on 20 May 2013, 02:58 PM
Hello,

Indeed in order to achieve the desired behavior you will need to set the OpenDropDownOnFocus, SelectAllTextEvent, and IsEditable of the RadComboBox control and in the code behind just set the SelectedIndex and the focus. The next code snippet was tested on our side and works as expected:
in the xaml:
<Button Content="Focus RadComboBox" Click="Button_Click_1"/>
<telerik:RadComboBox OpenDropDownOnFocus="True"
                        SelectAllTextEvent="GotFocus"
                        IsEditable="True"
                        x:Name="ComboBox"
                       .../>

and in the code behind:
private void Button_Click_1(object sender, RoutedEventArgs e)
{
    this.ComboBox.SelectedIndex = 2;
    this.ComboBox.Focus();
}

Hope this is helpful.

Regards,
Vladi
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
ComboBox
Asked by
Patrik
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Vladi
Telerik team
Share this question
or