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

RadTextBox: Getting and setting Focus

11 Answers 1224 Views
TextBox
This is a migrated thread and some comments may be shown as answers.
JanV
Top achievements
Rank 1
JanV asked on 27 May 2010, 08:51 AM
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

11 Answers, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 01 Jun 2010, 03:24 PM
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.
0
Celeste Zietsman
Top achievements
Rank 2
answered on 18 Nov 2011, 11:26 AM
Is this really the only way to set the focus of the textbox?
0
Peter
Telerik team
answered on 21 Nov 2011, 04:43 PM
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.

0
Celeste Zietsman
Top achievements
Rank 2
answered on 23 Nov 2011, 07:30 AM
Hi Peter

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

Thanks
0
Peter
Telerik team
answered on 25 Nov 2011, 05:42 PM
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.

0
Niska
Top achievements
Rank 1
answered on 13 Feb 2012, 12:57 PM
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.
0
Nikolay
Telerik team
answered on 13 Feb 2012, 04:25 PM
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 >>
0
Eric
Top achievements
Rank 1
answered on 24 Apr 2012, 12:55 AM
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>
0
Nikolay
Telerik team
answered on 25 Apr 2012, 11:14 AM
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 >>
0
yakesh
Top achievements
Rank 1
answered on 26 Oct 2017, 01:32 PM

Hi,

how to set focus on the Radtextbox in edge browser

0
Hristo
Telerik team
answered on 27 Oct 2017, 05:40 AM
Hello Yakesh,

Thank you for writing.

This thread is discussing the RadTextBox for WinForms. Please check the product you are using and post your question in the proper forums.

I hope this helps.

Regards,
Hristo
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
TextBox
Asked by
JanV
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Celeste Zietsman
Top achievements
Rank 2
Peter
Telerik team
Niska
Top achievements
Rank 1
Eric
Top achievements
Rank 1
yakesh
Top achievements
Rank 1
Hristo
Telerik team
Share this question
or