Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / December 2005

Tip: Looking for answers? Try searching our database.

How to handle the CTRL+A keys?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sharon - 22 Dec 2005 07:04 GMT
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
Kevin Yu [MSFT] - 22 Dec 2005 08:34 GMT
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/microsoft.public.dotnet.framework.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
Signature

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

Justin Creasy - 22 Dec 2005 14:27 GMT
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
     }
}
Sharon - 22 Dec 2005 14:59 GMT
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
Justin Creasy - 22 Dec 2005 17:26 GMT
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
rossum - 28 Dec 2005 20:26 GMT
>Thanks for try Justin,
>But when the CTRL key is pressed down --> the event is fired, but the A key
[quoted text clipped - 18 lines]
>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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.