RadTextBox: Getting and setting Focus

10 posts, 0 answers
  1. JanV
    JanV avatar
    3 posts
    Member since:
    Sep 2009

    Posted 27 May 2010 Link to this post

    Hello,

    I've been having some issues getting and setting the Focus on a RadTextBox control.

    What's the best way to do this? Use the .Focus or the .Select method to set it?

    This forum contains some conflicting info:
    1. http://www.telerik.com/community/forums/winforms/editors/radtextbox-focus.aspx => "In order to set the focus to a RadTextBox when the form is loaded, please call its Select() method"

    2. http://www.telerik.com/community/forums/winforms/ui-controls/radtextbox-focus.aspx => "Yes, you can use the Focus method exactly as with MS textbox."



    Which one of the following properties is appropriate to get the control with the current focus?
    • RadTextBox.Focused
    • RadTextBox.TextBoxElement.IsFocused
    • RadTextBox..TextBoxElement.TextBoxItem.IsFocused

    Greetings,

    Jan
  2. Nikolay
    Admin
    Nikolay avatar
    1803 posts

    Posted 01 Jun 2010 Link to this post

    Hello JanV,

    Thank you for the question.

    The Focus or Select methods may or may not work depending on the place where they are called. For example you can select MS TextBox only if you call Select in the form constructor:

    However, if you want to call Focus method, you should do it at Form_Shown. Otherwise, you will not focus the textbox.

    Considering the fact that we are hosting the standard TextBox in RadTextBox, you can set the focus to RadTextBox by calling the Select method of the hosted control:
    public Form1()
    {
        InitializeComponent();
      
        this.radTextBox1.TextBoxElement.TextBoxItem.HostedControl.Select();      
    }

    The other way to set the focus to RadTextBox is by calling the Focus method of the hosted control in the Form_Shown:
    void Form1_Shown(object sender, EventArgs e)
    {
        this.radTextBox1.TextBoxElement.TextBoxItem.HostedControl.Focus();
    }

    I hope this helps.

    Sincerely yours,
    Nikolay
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Celeste Zietsman
    Celeste Zietsman avatar
    17 posts
    Member since:
    Apr 2010

    Posted 18 Nov 2011 Link to this post

    Is this really the only way to set the focus of the textbox?
  5. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 21 Nov 2011 Link to this post

    Hello Celeste,

    Thank you for writing.

    In the versions prior to Q3 2011 you should use RadTextBox's hosted control, for example

    this.radTextBox1.TextBoxElement.TextBoxItem.HostedControl.Select();

    In Q3 2011 you can call directly RadTextBox's Focus method or RadTextBox's Select method.

    I hope this helps.

     Regards,
    Peter
    the Telerik team

    Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

  6. Celeste Zietsman
    Celeste Zietsman avatar
    17 posts
    Member since:
    Apr 2010

    Posted 23 Nov 2011 Link to this post

    Hi Peter

    Thank you for the update. I have managed to get it working with the select method after installing Q3 2011.

    Thanks
  7. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 25 Nov 2011 Link to this post

    Hello Celeste,

    I am happy to hear that you managed to get it working.

    Do not hesitate to write me back if you have further questions.

    Best wishes,
    Peter
    the Telerik team

    Q3’11 of RadControls for WinForms is available for download (see what's new). Get it today.

  8. Niska
    Niska avatar
    7 posts
    Member since:
    Feb 2012

    Posted 13 Feb 2012 Link to this post

    Hi,

    I'm trying to know if radTextBox is focused - on client side,
    the radTextBox.Focused rerturns 'false', but the "_focused" property holds 'true' (which is private property and I can't have this value)
    is there any way to get the right indication about this textBox focusing??

    It's very important to me!


    thanks!
    Niska.
  9. Nikolay
    Admin
    Nikolay avatar
    1803 posts

    Posted 13 Feb 2012 Link to this post

    Hi Niska,

    The 'client side' phrase make me think that your question is related to our ASP.NET suite. If this is so, please open a new thread in the appropriate forum section as the current section is for RadControls for WinForms only.

    Thank you for your understanding.

    Kind regards,
    Nikolay
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  10. Eric
    Eric avatar
    24 posts
    Member since:
    Jul 2011

    Posted 23 Apr 2012 Link to this post

    I would like to second Celeste's statement:

    "Is this really the only way to set the focus of the textbox?"

    Control.Focus has been around for years and is therefore intuitive.  Please consider sparing us the implementation details and encapsulating that mess for use by creating a public "Focus" method that does whatever internal call needed.  This is the purpose behind "Information Hiding", see http://en.wikipedia.org/wiki/Information_hiding .

    </soapbox>
  11. Nikolay
    Admin
    Nikolay avatar
    1803 posts

    Posted 25 Apr 2012 Link to this post

    Hi Eric,

    Thank you for writing.

    As my colleague Peter mentioned in one of his previous responses, the Focus method has been introduced in Q3 2011 and it works just like it does for the standard TextBox control. Still, you are right that there is an issue after all - the Focus method is not currently visible in the code editor. We will address this accordingly. You should have no issues, however, if you explicitly type "Focus()" after a RadTextBox instance. In other words, you will not get any compile errors and the method will work as expected.

    I hope this clarifies the situation.

    Greetings,
    Nikolay
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
Back to Top
UI for WinForms is Visual Studio 2017 Ready