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

How to move between tab stops programatically

1 Answer 53 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 18 Oct 2011, 03:36 PM
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?

Thanks,
David

1 Answer, 1 is accepted

Sort by
0
Ivan Petrov
Telerik team
answered on 21 Oct 2011, 12:44 PM
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.

Tags
General Discussions
Asked by
David
Top achievements
Rank 1
Answers by
Ivan Petrov
Telerik team
Share this question
or