How to set keyboard focus to a specific DataFormField?

4 posts, 0 answers
  1. Jeff
    Jeff avatar
    100 posts
    Member since:
    Apr 2008

    Posted 11 Aug Link to this post

    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?

  2. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    371 posts

    Posted 15 Aug Link to this post

    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.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Jeff
    Jeff avatar
    100 posts
    Member since:
    Apr 2008

    Posted 15 Aug in reply to Dilyan Traykov Link to this post

    When I try this, dataForm.ChildrenOfType<DataFormDataField>() returns null.
  5. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    371 posts

    Posted 16 Aug Link to this post

    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.
Back to Top