Select all text on focus

4 posts, 0 answers
  1. Fabio
    Fabio avatar
    8 posts
    Member since:
    Jul 2010

    Posted 20 Nov 2012 Link to this post

    Hello,
    I have a RadAutocompleteBox and I'm looking for a way to select all text on focus.
    I looked for SelectAll() method but there's not one. Is there a way to do this?

    Thank you in advance
    Best regards
    Fabio
  2. Mike
    Mike avatar
    39 posts
    Member since:
    May 2011

    Posted 21 Nov 2012 Link to this post

  3. Heath
    Heath avatar
    3 posts
    Member since:
    Feb 2014

    Posted 21 Jul Link to this post

    Does something like this work (untested - need using Telerik.Windows.Controls;)

    var autoComplete = (RadAutoCompleteBox)sender;
    var textBox = autoComplete.ChildrenOfType<TextBox>().First();
    textBox.SelectAll();

  4. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    1033 posts

    Posted 24 Jul Link to this post

    Hello Heath,

    Indeed, a similar approach would work with the only specific being that the SelectAll method needs to be invoked through the Dispatcher:

    private void RadAutoCompleteBox_GotFocus(object sender, RoutedEventArgs e)
    {
        var autoComplete = (RadAutoCompleteBox)sender;
        var textBox = autoComplete.ChildrenOfType<TextBox>().First();
        Dispatcher.BeginInvoke(new Action(() =>
        {
            textBox.SelectAll();
        }));
    }

    Regards,
    Dilyan Traykov
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top