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

Highlight text when clicking back on box

1 Answer 59 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
Russ
Top achievements
Rank 1
Iron
Russ asked on 03 Mar 2014, 11:07 PM
I am using the rest of the AutoCompleteBox without issues. I do have one issue.  After a user is finished making a selection and comes back later to use the Box again, they click on the box, but the 'old' text is still there.  Is there a way to have AutoCompleteBox highlight all the text in the box when it gets the focus again?  Right now it just puts the cursor at the end of the line.

Thanks,

Russ

1 Answer, 1 is accepted

Sort by
0
Kalin
Telerik team
answered on 06 Mar 2014, 11:55 AM
Hello Russ,

You can achieve the desired behavior by getting the WatermarkTextBox from the AutoCompleteBox template and setting its SelectionOnFocus property to SelectAll. However you would need to do in the Loaded event handler of the AutoCompleteBox. So if you have the following AutoCompleteBox:

<telerik:RadAutoCompleteBox Loaded="auto_Loaded" x:Name="auto" ItemsSource="{Binding Items}" SelectionMode="Single" />

The Loaded handler should look like shown below:

private void auto_Loaded(object sender, RoutedEventArgs e)
{
    var textBox = this.auto.ChildrenOfType<RadWatermarkTextBox>().First();
    textBox.SelectionOnFocus = SelectionOnFocus.SelectAll;
}

This way the text will be highlighted whenever the AutoCompleteBox got the focus.

Hope this helps.

Regards,
Kalin
Telerik

DevCraft Q1'14 is here! Join the free online conference to see how this release solves your top-5 .NET challenges. Reserve your seat now!

Tags
AutoCompleteBox
Asked by
Russ
Top achievements
Rank 1
Iron
Answers by
Kalin
Telerik team
Share this question
or