jmayor
jmayor

Reputation: 2795

How to catch on a winform when the TAB key is pressed

I developed a Grid Control and I want that when Tab is pressed it jumps from on cell ot another. The issue is that no matters what event I suscribe or I override on the control when tab is pressed it never gets called. I also try to catch the Tab at the Form level but it's the same , any Key events respond to the TAB. Any suggestions?

Upvotes: 1

Views: 3637

Answers (4)

JohnForDummies
JohnForDummies

Reputation: 980

Have you tried overriding ProcessCmdKey?

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
    if(GridControlFocused)
    {
        switch(keyData)
        {
           case Keys.Tab:
           // put code here to jump to next cell.
           return true;
        }
    }

    return base.ProcessCmdKey(ref msg, keyData);
}

Upvotes: 1

Dan Byström
Dan Byström

Reputation: 9244

Have you tried to override IsInputKey?

Upvotes: 4

PerlDev
PerlDev

Reputation: 437

Either PreviewKeyDown or KeyPress should work for you. Are you sure your GridControl got focus while you tested your code?

Upvotes: 1

CesarGon
CesarGon

Reputation: 15325

Set Form.KeyPreview = false.

Upvotes: 0

Related Questions