We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Custom cell renderer and key events

I''m building my own cell renderer which hosts a specific type of control. I''ve noticed that if I press enter or the arrow keys while my control has focus, the grid will intercept the key press and do what it would normally do with it and my control never sees those keys. Normal keys work as expected, it''s just special keys like enter, arrows, escape, etc.

What do I have to do in my cell renderer to pass these key events onto my control and not have the grid see and use them.

Thanks.

1 Reply

AD Administrator Syncfusion Team August 9, 2006 10:42 AM UTC

Hi Amit,

Since Grid hosts your control inside the cell, it will use the keys navigation keys to move between the cells and will not pass on to the custom Control. So if the Control (CurrentCell) is in focus, then we need to programmatically do the required functions.

You can try setting the Grid.WantKeys flag to true in the ProcessKeyEventArgs override and revert it back to false in the Keyup event of the custom control, so that the key messages will not be processed by grid.
If you set WantKeys property of the grid to false, the grid will not process any keys like, TAB, arrow keys, Esc, etc.

protected override void OnInitialize(int rowIndex, int colIndex)
{
//
this.Control.KeyUp += new KeyEventHandler(Control_KeyUp);
}

protected override bool ProcessKeyEventArgs(ref System.Windows.Forms.Message m)
{
Keys keyCode = (Keys) ((int) m.WParam) & Keys.KeyCode;

if (m.Msg == 256 && keyCode == Keys.Tab)
{
this.Grid.WantKeys = true;
}
else
this.Grid.WantKeys = false;
//
}

void Control_KeyUp(object sender, KeyEventArgs e)
{
this.Grid.WantKeys = true;
}

Let me know if this helps.
Thanks,
Rajagopal

Loader.
Live Chat Icon For mobile
Up arrow icon