CutPaste

Hi,

How can i control CTRL+X or CTRL+V in KeyDown Event...

Thanks,
Surti

5 Replies

AD Administrator Syncfusion Team December 5, 2006 04:18 AM UTC

Hi Surti,

To control the +V,+C keystroke in KeyDown event, you need to find the keystroke and set e.Handled = true to cancel the default behavior. Here is a code snippet to show this.

private void gridControl1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
Keys modifierKeys = Control.ModifierKeys;
Keys keyCode = e.KeyCode & Keys.KeyCode;
bool controlKeyDown = (e.Modifiers & Keys.Control) != Keys.None;
bool menuKeyDown = (e.Modifiers & Keys.Menu) != Keys.None;
switch (keyCode)
{
case Keys.V: // +V
if (controlKeyDown && !menuKeyDown)
{
Console.WriteLine("+V Pressed");
e.Handled = true;
}
break;
case Keys.C: // +C
if (controlKeyDown && !menuKeyDown)
{
Console.WriteLine("+C Pressed");
e.Handled = true;
}
break;
case Keys.X: // +X
if (controlKeyDown && !menuKeyDown)
{
Console.WriteLine("+X Pressed");
e.Handled = true;
}
break;
}
}
}

Best Regards,
Haneef


AD Administrator Syncfusion Team December 5, 2006 09:16 AM UTC

Thanks, i had some similar but it doesn't work well when +X, +V or +C are pressed because the value of KeyCode is "Control", not "X", "V", or "C".
Nevertheless, when any other key is pressed, the value of keycode is correct.

Thanks,
Surti.


>Hi Surti,

To control the +V,+C keystroke in KeyDown event, you need to find the keystroke and set e.Handled = true to cancel the default behavior. Here is a code snippet to show this.

private void gridControl1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
Keys modifierKeys = Control.ModifierKeys;
Keys keyCode = e.KeyCode & Keys.KeyCode;
bool controlKeyDown = (e.Modifiers & Keys.Control) != Keys.None;
bool menuKeyDown = (e.Modifiers & Keys.Menu) != Keys.None;
switch (keyCode)
{
case Keys.V: // +V
if (controlKeyDown && !menuKeyDown)
{
Console.WriteLine("+V Pressed");
e.Handled = true;
}
break;
case Keys.C: // +C
if (controlKeyDown && !menuKeyDown)
{
Console.WriteLine("+C Pressed");
e.Handled = true;
}
break;
case Keys.X: // +X
if (controlKeyDown && !menuKeyDown)
{
Console.WriteLine("+X Pressed");
e.Handled = true;
}
break;
}
}
}

Best Regards,
Haneef


AD Administrator Syncfusion Team December 5, 2006 11:16 AM UTC

Hi, the code you sendme doesn´t work well because when i press "CTRL" with one of these keys (X, V or C) value of keycode is "Control", not "X", "V" or "C". Do you know why???

Thanks,
Surti.


AD Administrator Syncfusion Team December 5, 2006 11:32 AM UTC

Hi Surti,

We tried to reproduce this in V4.x by just implement KeyDown event in a GridControl, but could not get this issue. Maybe I am not following the steps that you are doing. Attached sample working fine here. Can you post a small sample showing this problem or tell us how to see it in the Browser sample/Attached sample?

Here is a sample for implementing it.
GC_KeyDownevent.zip

If you can provide more information, we can try to suggest some solution.

Regards,
Haneef


AD Administrator Syncfusion Team December 5, 2006 11:46 AM UTC

Hi,

I have Essential Suite 1.5.1.1.
I have same code that you send me but when i press the combination of CTRL with one of these three keys, the value of keycode, in keydown event, is "Control".

Previosly i had configured following properties of GC,

GridControl1.WantTabKey = false
GridControl1.NumberedColHeaders = false

Thanks,
Surti

PD: Sorry for my english.

Loader.
Up arrow icon