This is a migrated thread and some comments may be shown as answers.

Problem with RadTextBox.Focused in Telerik 2010Q1

5 Answers 387 Views
TextBox
This is a migrated thread and some comments may be shown as answers.
Gabriele Svelto
Top achievements
Rank 1
Gabriele Svelto asked on 03 May 2010, 09:37 AM
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.

5 Answers, 1 is accepted

Sort by
0
Jason Maronge
Top achievements
Rank 1
answered on 05 May 2010, 05:44 PM
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
0
Accepted
Deyan
Telerik team
answered on 06 May 2010, 09:43 AM
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.
0
Gabriele Svelto
Top achievements
Rank 1
answered on 06 May 2010, 09:56 AM
Thank you Deyan, ContainsFocus was exactly what I was looking for.
0
Niska
Top achievements
Rank 1
answered on 15 Feb 2012, 10:12 AM

Hi,

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

is there any other function for me?

thanx!
0
Nikolay
Telerik team
answered on 15 Feb 2012, 10:27 AM
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 >>
Tags
TextBox
Asked by
Gabriele Svelto
Top achievements
Rank 1
Answers by
Jason Maronge
Top achievements
Rank 1
Deyan
Telerik team
Gabriele Svelto
Top achievements
Rank 1
Niska
Top achievements
Rank 1
Nikolay
Telerik team
Share this question
or