473,379 Members | 2,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

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 27219
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sylwia | last post by:
Hi! I'm writing an application that runs in a 'Full screen' mode. I do not want any other windows (as well as the desktop) to be accessible while my application is running. My problem is that...
3
by: Coder | last post by:
hi, there is still no answer, i wonder if there is a way to handle the multiple key-press event on a C# windows form, like "Ctrl+Enter"
3
by: Mark | last post by:
Any Visual C++ source code available for disabling the following keys in windows 2000. Alt + Ctrl + Del Ctrl + Esc Windows Key to Remove task bar Function keys (or Alt + Function keys or Ctrl...
9
by: Miky | last post by:
Hi, I need to send Ctrl-PgUp (or Ctrl-PgDown) to the active application but when I use SendKeys.Send("^{PGUP}"), the program understands it as just PageUp. How may I solve it? Thanks in...
3
by: Pooja | last post by:
Hi guys, I have been struggling with this problem for quite a sometime now. Before a state down my problem wanna give an exmaple: 1. Open a MsWord document. 2. Open the Page Setup dialog box....
1
by: Emma Middlebrook | last post by:
Hi there, I'm trying to handle some shortcut keys within my application and I can't seem to get the code to work when you are trying to action against a ctrl + other character. I found a post...
1
by: phcmi | last post by:
Within a mousedown event, can you please show a code sample of how to ascertain whether the CTRL and/or ALT and/or SHIFT keyboard key is pressed? Thank you
2
by: Charles Law | last post by:
I'll kick myself when you tell me, but ... I have a user control on a form, and I want the user control to see the arrow keys when I press them. If I press just about any other key the control's...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.