Winforms setting focus to textbox

2 posts, 0 answers
  1. Johan
    Johan avatar
    11 posts
    Member since:
    Mar 2008

    Posted 11 Jul 2008 Link to this post

    Hello,

    I have a RadTextBoxElement within a RadToolStripItem. When a specific button is pressed I want the text box to receive focus, but the focus method returns false (and doesn't do anything).
    I have tried setting CanFocus, Enabled and Visibility to true and visible but the focus method still doesn't work. Any ideas on how to make it work?
  2. Nikolay
    Admin
    Nikolay avatar
    1803 posts

    Posted 14 Jul 2008 Link to this post

    Hello Johan,

    In order to focus the text box, you should call the Focus() method of the RadTextBoxElement.TextBoxItem:
    radTextBoxElement1.TextBoxItem.Focus(); 

    The above will focus the text box with its whole text selected. Should you prefer to have no text selected, or only a part of it selected, call the Select() method passing the appropriate selection values:
    radTextBoxElement1.TextBoxItem.Focus();  
    radTextBoxElement1.TextBoxItem.Select(0, 0); 

    If you have additional questions, feel free to contact me.

    Sincerely yours,
    Nikolay
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top