Problem with RadTextBox.Focused in Telerik 2010Q1

6 posts, 1 answers
  1. Gabriele Svelto
    Gabriele Svelto avatar
    6 posts
    Member since:
    Sep 2009

    Posted 03 May 2010 Link to this post

    I have a piece of code that refreshes a RadTextBox Text property depending on external events. In order not to change the Text property while the user is typing in the text box I check the Focused property first and proceed in overwriting the Text property only if it is false, the relevant code looks like this:

    private void event_ExternalUpdate(object sender, EventArgs args) 
        if (!textBox.Focused) 
            textBox.Text = "foo"
     

    However in Telerik 2010Q1 this does not seem to work. I have tried to check at runtime and apparently the Focused property is always false even though I am editing that particular text-box. I have made a super-simplified test case and tried it with both Telerik 2009Q3 and 2010Q1 and it works correctly under version 2009Q3 (Focused is set to true when I'm typing in the field) but not on 2010Q1. Is this a bug or is there another way to check if a specific control has the input focus?

    As a temporary workaround I noticed that the FocusedElement property is null when the text-box doesn't have the input focus and points to the embedded RadTextBoxItem when it has focus so I'm using it instead. However because FocusedElement is not documented I am a bit wary of using it.
  2. Jason Maronge
    Jason Maronge avatar
    322 posts
    Member since:
    Jan 2005

    Posted 05 May 2010 Link to this post

    I am having a similar issue.  No matter what I do I can't get the RadTextBox to focus in code.

    Here is what I am trying to do:

            public void SetFocus() 
            { 
                ActiveControl = txtCode; 
                txtCode.Focus(); 
                txtCode.Select(); 
                txtCode.SelectAll(); 
                txtCode.TextBoxElement.Focus(); 
                txtCode.TextBoxElement.Select(); 
                txtCode.TextBoxElement.TextBoxItem.Focus(); 
                txtCode.TextBoxElement.TextBoxItem.Select(); 
                txtCode.TextBoxElement.TextBoxItem.SelectAll(); 
            }  

    You would think that one of those calls would set focus to the control.  Something is broken with the focus

    Jason
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Answer
    Deyan
    Admin
    Deyan avatar
    2037 posts

    Posted 06 May 2010 Link to this post

    Hi Gabriele and Jason,

    As of Q1 2010 we introduced some changes in the way the RadTextBox control handles the focus. Since there were certain issues with the GotFocus and LostFocus events, as well as the Focus method, we decided to revisit the logic and improve it. The RadTextBox control hosts a standard TextBox control and extends its functionality by providing support for the Telerik Presentation Framework (theming, dependency properties etc.). Since the control itself is not the focused control (but the TextBox inside) the Focused property will not be set to true. However, you can use the ContainsFocus property. This property will always be true when a control inside the current control is focused. Take a look at the following code snippet:

    void radTextBox1_TextChanged(object sender, EventArgs e)
    {
        if (this.radTextBox1.ContainsFocus)
        {
     
        }
    }


    As for the Focus method, I tried to reproduce the issue with calling it and not getting the control focused but to no avail. The Focus method works as expected for me:

    this.radTextBox2.Focus();

    This correctly puts the focus into the control.

    Jason, could you please share with me further details on your scenario so that I can make sure that I correctly try to reproduce the issue?

    Best wishes,
    Deyan
    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.
  5. Gabriele Svelto
    Gabriele Svelto avatar
    6 posts
    Member since:
    Sep 2009

    Posted 06 May 2010 Link to this post

    Thank you Deyan, ContainsFocus was exactly what I was looking for.
  6. Niska
    Niska avatar
    7 posts
    Member since:
    Feb 2012

    Posted 15 Feb 2012 Link to this post


    Hi,

    I'm working from the aspx page - client side,
    and the 'ContainsFocus' is undefined

    is there any other function for me?

    thanx!
  7. Nikolay
    Admin
    Nikolay avatar
    1803 posts

    Posted 15 Feb 2012 Link to this post

    Hi Niska,

    Please note that this thread concerns RadControls for WinForms. If your question is about our ASP.NET suite, please address it in the appropriate forum section.

    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 >>
Back to Top
UI for WinForms is Visual Studio 2017 Ready