Discussion:
DataGridView - changing Tab key and Enter key behavior
(too old to reply)
proxyuser
2009-09-10 21:38:08 UTC
Permalink
I want the enter key to work like the tab key, and the tab key to just skip
out of the control.

The latter is easily solved by changing the StandardTab property to True.

Then I derived a class from DataGridView and overrode the ProcessDialogKey
and ProcessDataGridViewKey methods. Then I handle the Enter key behavior.
But of course I can't just tell it to behave like the Tab key, because now
the Tab key works differently because of the StandardTab setting. I tried
this, but it doesn't work. Any other ideas?

protected override bool ProcessDialogKey( Keys keyData )

{

if ( keyData == Keys.Enter )

{

StandardTab = false;

bool retCode = base.ProcessTabKey(Keys.Tab);

StandardTab = true;

return retCode;

}

return base.ProcessDialogKey(keyData);

}
Eddie
2009-09-11 11:55:34 UTC
Permalink
Post by proxyuser
I want the enter key to work like the tab key, and the tab key to just skip
out of the control.
The latter is easily solved by changing the StandardTab property to True.
Then I derived a class from DataGridView and overrode the ProcessDialogKey
and ProcessDataGridViewKey methods. Then I handle the Enter key behavior.
But of course I can't just tell it to behave like the Tab key, because now
the Tab key works differently because of the StandardTab setting. I tried
this, but it doesn't work. Any other ideas?
Have a look at the DataGridView class in Reflector. You'll see that the
ProcessTabKey() method calls the private methods TabToNextCell() or
TabToPreviousCell(), depending on which modifier keys are pressed.

You'll probably want your own implementation of TabToNextCell() and
TabToPreviousCell(), using the existing code in DataGridView as a
starting point for your implementation.
--
Eddie ***@deguello.org
proxyuser
2009-09-11 14:03:02 UTC
Permalink
Post by Eddie
Have a look at the DataGridView class in Reflector. You'll see that the
ProcessTabKey() method calls the private methods TabToNextCell() or
TabToPreviousCell(), depending on which modifier keys are pressed.
You'll probably want your own implementation of TabToNextCell() and
TabToPreviousCell(), using the existing code in DataGridView as a starting
point for your implementation.
OK thanks.

Loading...