469,292 Members | 1,306 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,292 developers. It's quick & easy.

How to handle the CTRL+A keys?

I’m using the DataGrid control. The DataGrid allow select all by clicking on
CTRL+A keys.
I need to catch this keys event, so I tried using the KeyDown event, but
only when the CTRL is pressed I get the event, but if the A key is pressed
while the CTRL is pressed – The event is not fired to my KeyDown handler.

How do I get the event for the CTRL + A keys?
---------
Thanks
Sharon
Dec 22 '05 #1
5 26507
Hi Sharon,

You cannot catch the ctrl+A event in the DataGrid level because it was
fired inside the TextBox of the cell. So in this case, you have to handle
the TextBox.KeyDown events to catch this or, you can use sub-class the
DataGrid to achieve this. Here is a thread similar to your requirements. I
think it will be helpful to you.

http://groups.google.com/group/micro...rk.windowsform
s.controls/browse_frm/thread/9f53c61f3e729ceb/bcdc1ec769d30da1?lnk=st&q=%22J
effrey+Tan%22+datagrid+processcmdkey&rnum=1&hl=zh-CN#bcdc1ec769d30da1

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Dec 22 '05 #2
Hey Sharon, if you're using the KeyDown event try this.

private void yourKeyDownEvent(object sender, KeyEventArgs e)
{
if(e.Control && e.Equals(Keys.A))
{
// your code here
}
}

Dec 22 '05 #3
Thanks for try Justin,
But when the CTRL key is pressed down --> the event is fired, but the A key
event is not firing the event because the CTRL key is still pressed.

I event changed the code to:
private void OnDataGridKeyDown(object sender,
System.Windows.Forms.KeyEventArgs e)
{
if( e.Equals(Keys.A) )
{
if( e.Control ) // It never gets in here !!!
{
// Some code...
}
}
}

I hope there is a solution for that.

------
Thanks
Sharon
Dec 22 '05 #4
Hey Sharon, sorry about that, I thought I saw it work but I'm doing it
now and it's not working.

I did some code awhile ago to do something like this but I can't seem
to find it. What you have to do is override some system commands
because you won't be able to use KeyDown or KeyPress. Once the control
key is it, pressing another key will not fire the keyDown event. I'll
look around some more, but for now I would focus on looking for the
lower level functions that get called when system keys (control, alt,
shift, etc.) are pressed. I'll post again if I find what I'm talking
about. good luck

Dec 22 '05 #5
On Thu, 22 Dec 2005 06:59:04 -0800, Sharon <Sh*****@newsgroups.nospam>
wrote:
Thanks for try Justin,
But when the CTRL key is pressed down --> the event is fired, but the A key
event is not firing the event because the CTRL key is still pressed.

I event changed the code to:
private void OnDataGridKeyDown(object sender,
System.Windows.Forms.KeyEventArgs e)
{
if( e.Equals(Keys.A) )
{
if( e.Control ) // It never gets in here !!!
{
// Some code...
}
}
}

I hope there is a solution for that.

------
Thanks
Sharon


Try overriding the ProcessDialogKey event:

bool ProcessDialogKey(Keys keyData)

For Ctrl-A use
if (keyData == Keys.Control | Keys.A) ...
or else
switch (keyData) { case Keys.Control | Keys.A: ...

Return true if you have processed the key, otherwise return
base.ProcessDialogKey(keyData) to give the rest of the system access
to the keystrokes you are not handling.

rossum

--

The ultimate truth is that there is no ultimate truth
Dec 28 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Sylwia | last post: by
3 posts views Thread by Coder | last post: by
9 posts views Thread by Miky | last post: by
1 post views Thread by Emma Middlebrook | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.