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

Set Focus

3 Answers 325 Views
DateTimePicker
This is a migrated thread and some comments may be shown as answers.
Rieni De Rijke
Top achievements
Rank 1
Rieni De Rijke asked on 23 Sep 2010, 09:28 AM
We have a RadDateTimePicker in a window.
When the window opens, we want to set focus on the RadDateTimePicker.
So we use 
         public OurWindow()
        {
            InitializeComponent();
            OurDateTimePicker.Focus();
        }
When openeing the window, we see the orange border (Office-theme) that indicates that the RadDateTimePicker has focus. When pushing the Arrow-Down-key the calendar opens. Great!
But, our customers also want the possibility to can write immediately in the box. How could we do this?
When we set focus from codebehind, the text in the box is not selected and there is no beam in the box.

We alse tried to set focus after the window was loaded and activated. 

3 Answers, 1 is accepted

Sort by
0
George
Telerik team
answered on 28 Sep 2010, 10:51 AM
Hello,

Thank you for contacting us.

To accomplish this, I would suggest you to use FindChildrenByType<>  method to find the TextBox, placed in the RadDateTimePicker control. Then, you could set the focus to this TextBox. For example:

var textbox = this.picker.FindChildByType<TextBox>();
            if (textbox != null)
            {
                textbox.Focus();
            }

Attached you can find the sample project. I hope this helps!


All the best,
George
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
Maurizio
Top achievements
Rank 1
answered on 21 May 2015, 09:02 AM

When I'm trying to give the focus to a RadDatePicker that is becoming visible for the first time, it happens that the textbox I am looking for (with FindChildByType) is null, probably because wpf is still in the process of creating it.

I even tried to delay the Focus using the dispatcher but nothing has changed.

After the first time the RadDatePicker has become visible, setting the focus works correctly.

0
Nasko
Telerik team
answered on 26 May 2015, 06:18 AM
Hi Maurizio,

We tested the proposed by George approach using the latest official released version 2015.1.401 and the Loaded event of RadDateTimePicker and it seems everything works as expected. Using the ChildrenOfType method we could get the TextBox and by using its Focus method the focus is set as expected:
private void radDateTimePicker_Loaded(object sender, RoutedEventArgs e)
{
    var dateTimePicker = sender as RadDateTimePicker;
 
    var textBox = dateTimePicker.ChildrenOfType<TextBox>().FirstOrDefault();
    textBox.Focus();
}

Could you please give a try again to the proposed approach using the provided above code - snippet and let us know if it worked for you?

Hopes this helps.

Regards,
Nasko
Telerik
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 Feedback Portal and vote to affect the priority of the items
Tags
DateTimePicker
Asked by
Rieni De Rijke
Top achievements
Rank 1
Answers by
George
Telerik team
Maurizio
Top achievements
Rank 1
Nasko
Telerik team
Share this question
or