Discussion:
Navigate With Arrow Keys
(too old to reply)
Derek Hart
2009-08-01 00:02:56 UTC
Permalink
I have a usercontrol that has 4 textboxes on it, and the usercontrol gets
added to a flowlayoutpanel. It looks just like a datagrid. I am trapping
keystrokes and don't know how to move to the next usercontrol, just like
arrows would do in a grid. The keydown code is on the textboxes, so I would
need to find the parent, which is the usercontrol, and then find the next
usercontrol. Please help with any code, or pseudo code.
Morten Wennevik [C# MVP]
2009-08-12 06:30:01 UTC
Permalink
Hi Derek,

Trapping the KeyDown event on the TextBox controls should let you find the
next control in the tab order by calling the GetNextControl method on the
parent control.

private void textBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Right)
{
TextBox tb = sender as TextBox;
Control c = tb.Parent;
Control next = c.GetNextControl(tb, true);
next.Focus();
}
}
--
Happy Coding!
Morten Wennevik [C# MVP]
Post by Derek Hart
I have a usercontrol that has 4 textboxes on it, and the usercontrol gets
added to a flowlayoutpanel. It looks just like a datagrid. I am trapping
keystrokes and don't know how to move to the next usercontrol, just like
arrows would do in a grid. The keydown code is on the textboxes, so I would
need to find the parent, which is the usercontrol, and then find the next
usercontrol. Please help with any code, or pseudo code.
Loading...