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

How to set keyboard focus to a specific DataFormField?

3 Answers 132 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 11 Aug 2016, 07:30 PM

I have a telerik:RadDataForm with an EditTemplate.

In that template I have a number of telerik:DataFormDataField's defined.

What I would like is to have the keyboard focus automatically set to one of these fields (not the first), when I do a BeginEdit().

How?

3 Answers, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 15 Aug 2016, 03:20 PM
Hello Jeff,

In order to achieve the desired behavior, you can handle RadDataForm's BeginningEdit event, like so:

public MainWindow()
{
    InitializeComponent();
    this.DataForm.BeginningEdit += DataForm_BeginningEdit;
}
 
private void DataForm_BeginningEdit(object sender, System.ComponentModel.CancelEventArgs e)
{
    var dataForm = sender as RadDataForm;
    var fields = dataForm.ChildrenOfType<DataFormDataField>();
    var field = fields.FirstOrDefault(x => x.Name == "Est");
    var textBox = field.FindChildByType<TextBox>();
    textBox.Focus();
}

Please let me know whether such an approach would work for you.

Regards,
Dilyan Traykov
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Jeff
Top achievements
Rank 1
answered on 15 Aug 2016, 04:16 PM
When I try this, dataForm.ChildrenOfType<DataFormDataField>() returns null.
0
Dilyan Traykov
Telerik team
answered on 16 Aug 2016, 07:58 AM
Hello Jeff,

I'm attaching a sample project where the ChildrenOfType method returns the expected result.

Could you please have a look at it and let me know whether it differs from the setup you have at your end in any way?

Thank you in advance for your cooperation.

Regards,
Dilyan Traykov
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
DataForm
Asked by
Jeff
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Jeff
Top achievements
Rank 1
Share this question
or