Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

DataGridView - changing Tab key and Enter key behavior

169 views
Skip to first unread message

proxyuser

unread,
Sep 10, 2009, 5:38:08 PM9/10/09
to
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

unread,
Sep 11, 2009, 7:55:34 AM9/11/09
to
proxyuser wrote:
> 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 ed...@deguello.org

proxyuser

unread,
Sep 11, 2009, 10:03:02 AM9/11/09
to

"Eddie" <ed...@deguello.org> wrote in message
news:seqpn6-...@deguello.org...

> proxyuser wrote:
>
> 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.


0 new messages