How to move between tab stops programatically

2 posts, 0 answers
  1. David
    David avatar
    3 posts
    Member since:
    Jun 2012

    Posted 18 Oct 2011 Link to this post

    I have a form that is basically a fancy data entry form where the user would like to press enter to move between the fields.

    I have dropdowns, spinners, textboxes, etc and I need to create this functionality.

    Now with regular .NET controls there is a simple method SelectNextControl that I could use.

    When I trigger the keypress event on a drop down the sender is a RadDropDownTextBoxElement which cannot be cast into a base Control object so I cannot get access to the SelectNextControl method.

    I know there should be an easy way to do this, but, so far, I have been able to find it.

    Can you help?

  2. Ivan Petrov
    Ivan Petrov avatar
    701 posts

    Posted 21 Oct 2011 Link to this post

    Hello David,

    Thank you for writing.

    The issue comes from the fact that we host a standard text box inside our RadTextBox. This hosted control is the actual tab stop, not the RadControl that hosts it. This is why you have to subscribe to the hosted control's KeyPress event and from there to select the next control. Here is a snippet which demonstrates this for a RadTextBox, RadSpinEditor and RadDropDownList:

    this.radTextBox1.TextBoxElement.TextBoxItem.HostedControl.KeyPress += new KeyPressEventHandler(HostedControl_KeyPress);
    this.radSpinEditor1.SpinElement.TextBoxItem.HostedControl.KeyPress += new KeyPressEventHandler(HostedControl_KeyPress);
    this.PhonesDDL.DropDownListElement.TextBox.TextBoxItem.HostedControl.KeyPress += new KeyPressEventHandler(HostedControl_KeyPress);
    private void HostedControl_KeyPress(object sender, KeyPressEventArgs e)
      if (e.KeyChar == (char)Keys.Enter)
        Control control = sender as Control;
        if (control != null)
          this.SelectNextControl(control, true, true, true, true);

    I hope this will help you. if you have further questions, I would be happy to help. Best wishes,
    Ivan Petrov
    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.

Back to Top