How to select a textbox inside a page?

4 posts, 1 answers
  1. George Saveliev
    George Saveliev avatar
    29 posts
    Member since:
    May 2009

    Posted 08 Feb 2011 Link to this post

    Hello!

    If I create a simple RadForm with a single RadTextBox, this text box is selected (gets input focus and shows cursor) automatically when the form is shown. If I create a simple RadForm with a RadPageView and place the RadTextBox into the page, it is not selected automatically when the form is shown.

    Even the following code does not select the text box:

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
     
        radTextBox1.Focus();
        radTextBox1.Select(0, 0);
    }

    The following workaround does work, but I do not think this is a way I should go:

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
     
        Application.Idle += Application_Idle;
    }
     
    void Application_Idle(object sender, EventArgs e)
    {
        Application.Idle -= Application_Idle;
        radTextBox1.Focus();
        radTextBox1.Select(0, 0);
    }

    So, how should I correctly select the text box in the PageView page when the form is shown?

    Thank you.

  2. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 08 Feb 2011 Link to this post

    Hello,

    It should be fine if you move the code
    radTextBox1.Focus(); 
    radTextBox1.Select(0, 0); 
    to the FormShown event, not the FormLoad event.

    Hope that helps
    Richard
  3. UI for WinForms is Visual Studio 2017 Ready
  4. George Saveliev
    George Saveliev avatar
    29 posts
    Member since:
    May 2009

    Posted 08 Feb 2011 Link to this post

    Thank you!

  5. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 08 Feb 2011 Link to this post

    Glad I could be of help, George.
    Richard
Back to Top