Hi,
I have a custom cell renderer derived from GridStaticCellRenderer that contains one of several possible controls. These controls are generally a user control containing a single edit. My render goes into edit mode when it is double clicked but the problem I''m having is when one of the navigation keys (left.right etc.) is pressed the grid moves the focused cell. I would like these keypress to be handled by the control but the grid seems to deal with them first.
Any ideas?
Thanks andy
AD
Administrator
Syncfusion Team
November 28, 2005 02:18 PM UTC
Try overriding the ProcessKeyEventArgs method in your renderer class. Take a look at the \Essential Suite\Windows\Grid.Windows\Samples\In Depth\GridInCells sample. It has a custom celltype that allows a grid in a cell, and has this method overridden in the renderer so the embedded grid gets like the arrow keys.
AW
Andrew Westacott
November 28, 2005 03:23 PM UTC
Thanks for the quick reply.
I can''t see how I''m supposed to pass the keyboard message onto an underlying control (textBox for example)?
Andy
>Try overriding the ProcessKeyEventArgs method in your renderer class. Take a look at the \Essential Suite\Windows\Grid.Windows\Samples\In Depth\GridInCells sample. It has a custom celltype that allows a grid in a cell, and has this method overridden in the renderer so the embedded grid gets like the arrow keys.
AD
Administrator
Syncfusion Team
November 28, 2005 03:54 PM UTC
The way the sample does it is to derive the Control (a GridControl in the sample), add a public (or internal as in the sample) method InitiateProcessKeyEventArgs that accesses the protected ProcessKeyEventArgs method of the Control. Then in the ProcessKeyEventArgs override in the renderer, it calls this InitiateProcessKeyEventArgs method to forward teh keys onto the Control. Here is another forum thread on this but it gives the same type of information. http://www.syncfusion.com/Support/forums/message.aspx?MessageID=8961
AW
Andrew Westacott
November 28, 2005 04:26 PM UTC
Sorry still no luck.
I setup a little test app that created a derived textbox with an InvokeProcessKeyEventArgs that looked like this:
public bool InvokeProcessKeyEventArgs( ref Message m )
{
return base.ProcessKeyEventArgs (ref m);
}
I then have a button on my form that would hopefully fake the keypress:
private void button1_Click(object sender, System.EventArgs e)
{
Message m = new Message();
m.Msg = 0x100;
m.LParam = IntPtr.Zero;
m.WParam = new IntPtr( ''X'' );
textBox1.InvokeProcessKeyEventArgs( ref m );
}
This doesn''t do anything.
Andy
>The way the sample does it is to derive the Control (a GridControl in the sample), add a public (or internal as in the sample) method InitiateProcessKeyEventArgs that accesses the protected ProcessKeyEventArgs method of the Control. Then in the ProcessKeyEventArgs override in the renderer, it calls this InitiateProcessKeyEventArgs method to forward teh keys onto the Control. Here is another forum thread on this but it gives the same type of information. http://www.syncfusion.com/Support/forums/message.aspx?MessageID=8961
AW
Andrew Westacott
November 28, 2005 04:32 PM UTC
I have also wired up the forms ProcessCmdKey to forward on the message to the textbox in the same way. I can see the keyboard events in the derived textbox but no changes to text itself.
>Sorry still no luck.
>
>I setup a little test app that created a derived textbox with an InvokeProcessKeyEventArgs that looked like this:
>
> public bool InvokeProcessKeyEventArgs( ref Message m )
> {
> return base.ProcessKeyEventArgs (ref m);
> }
>
>I then have a button on my form that would hopefully fake the keypress:
>
> private void button1_Click(object sender, System.EventArgs e)
> {
> Message m = new Message();
> m.Msg = 0x100;
> m.LParam = IntPtr.Zero;
> m.WParam = new IntPtr( ''X'' );
> textBox1.InvokeProcessKeyEventArgs( ref m );
> }
>
>This doesn''t do anything.
>
>Andy
>
>
>
>>The way the sample does it is to derive the Control (a GridControl in the sample), add a public (or internal as in the sample) method InitiateProcessKeyEventArgs that accesses the protected ProcessKeyEventArgs method of the Control. Then in the ProcessKeyEventArgs override in the renderer, it calls this InitiateProcessKeyEventArgs method to forward teh keys onto the Control. Here is another forum thread on this but it gives the same type of information. http://www.syncfusion.com/Support/forums/message.aspx?MessageID=8961
AD
Administrator
Syncfusion Team
November 28, 2005 05:26 PM UTC
Try setting focus to the control first to see if that affects this behavior. When you click a button, it gets input focus.
textBox1.Focus();
textBox1.InvokeProcessKeyEventArgs( ref m );
AW
Andrew Westacott
November 29, 2005 10:50 AM UTC
This still does not work. I cannot see how calling ProcessKeyEventArgs would cause the control to perform it''s action. All ProcessKeyEventArgs does is to fire the various OnKeyUp, OnKeyDown events. What I want is the actual keyboard events to be applied to the underlying control so for example if I press cursor right when the edit is active instead of the grid moving to the next cell I would like the cursor to move within the contained TextBox control.
Thanks for your help
Andy
>Try setting focus to the control first to see if that affects this behavior. When you click a button, it gets input focus.
>
>textBox1.Focus();
>textBox1.InvokeProcessKeyEventArgs( ref m );
>
>
AD
Administrator
Syncfusion Team
November 29, 2005 12:09 PM UTC
Take a look at this sample. \3.3.0.0\Windows\Grid.Windows\Samples\DataBound\RepeaterUserControlSample
It has textboxes where the left and right arrows are handled. It does all the work itself. Search for HandleKeyDown in the whole solution.
AW
Andrew Westacott
November 29, 2005 12:58 PM UTC
Ahhh ok so I would have to totally handle the cursor keys myself. Ok I''ll give it a go.
Thanks again
Andy
>Take a look at this sample. \3.3.0.0\Windows\Grid.Windows\Samples\DataBound\RepeaterUserControlSample
>
>It has textboxes where the left and right arrows are handled. It does all the work itself. Search for HandleKeyDown in the whole solution.