Multimobile Development: Building Applications for any Smartphone
System.Windows.Forms.DataGrid Does Not Raise KeyDown Event When Tab, Enter, or Arrow Keys Are Pressed
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.windowsforms.controls.


Chad Boschert
I am trying to change the behavior of the enter key within a DataGrid.
The default behavior drops the cursor to the next row - I want the
cursor to go to the next cell (just like the tab key.)

I have my event handler wired up to the KeyDown event of the
DataGridTextBox controls in my DataGrid. The event gets raised for
all keys accept the Tab, Enter, and Arrow Keys.

Any ideas as to how this can be accomplished?

-Chad Boschert
Reply to this message...
Vote that this is a GOOD answer...
 
Really good experience at the Apple Store
MonoDroid – looking *awesome*
 
    
Stephen Alpert
On 1 Jul 2003 08:30:02 -0700, Click here to reveal e-mail address (Chad Boschert) wrote:

[Original message clipped]

Chad: Those keys are normally form navigation keys and that's why you don't see
them. I don't have the answer to your question..

/steveA
my email Click here to reveal e-mail address is encrypted with ROT13 (www.rot13.org)
Reply to this message...
Vote that this is a GOOD answer...
 
First volume of Multimobile Development nearly ready to go to press
A mention on Developing for the iPhone and Android: The pros and cons
 
    
walter leinert
Hi Chad,

may be that you must set the AcceptsReturn property of the DataGridTextBox
to receive the event.

Walter

"Chad Boschert" <Click here to reveal e-mail address> schrieb im Newsbeitrag
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer...
 
 
    
Chad Boschert
Walter, that is a good idea but still doesn't seem to work. If I
enable the acceptstab property the event is raised for the tab key;
I'm not sure what is happening. I also tried enabling the multiline
property - no luck.

- Chad
Reply to this message...
Vote that this is a GOOD answer...
 
First chapters of Multimobile Development book now available on Apress Alpha program
iPad
 
    
Brendon Webber
What you need to do is actually capture the windows message and then process that event accordingly. Here is an example where the ProcessCmdKey method is overidden in a customised ComboBox class. Create a custom DataGrid class and override this method.

Hope this helps...

Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean
Dim bHandled As Boolean = False

Try

If bIsReadOnly Then
Return True
End If

If ((keyData = (Keys.Tab Or Keys.Shift)) And (Me.ModifierKeys = Keys.Shift)) Or (keyData = Keys.Left) Then
Return MyBase.ProcessCmdKey(msg, keyData)
ElseIf (keyData = Keys.Tab) Or (keyData = Keys.Enter) Or (keyData = Keys.Return) Then

msg.Result = IntPtr.Zero
If keyData = Keys.Tab Then
Dim e As New FocusChangeEventArgs(FocusDirection.Forward)
RaiseEvent LostFocus(Me, e)
If e.Handled Then
Return True
Else
Return MyBase.ProcessCmdKey(msg, keyData)
End If
Else
System.Windows.Forms.SendKeys.Send(Chr(9))
Return True
End If

Else
Return MyBase.ProcessCmdKey(msg, keyData)
End If

Catch ex As Exception
MsgBox(ex, , "Library > SComboBox > ProcessCmdKey")
End Try

End Function

--------------------------------
From: Brendon Webber
Reply to this message...
Vote that this is a GOOD answer...
 
New book project – Multimobile Development: Building Applications for any Smartphone
Dive into HTML5
 
 
System.IntPtr
System.Web.UI.WebControls.DataGrid
System.Windows.Forms.ComboBox
System.Windows.Forms.DataGrid
System.Windows.Forms.DataGridTextBox
System.Windows.Forms.Keys
System.Windows.Forms.Message
System.Windows.Forms.SendKeys




Multimobile Development: Building Applications for any Smartphone
Ad
BootFX
Reliable and powerful .NET application framework.
iOS, Android and Windows Phone Development Training and Consultancy
Hosted by RackSRV Communications
 
Multimobile Development: Building Applications for any Smartphone
Copyright © AMX Software Ltd 2008-2010. Portions copyright © Matthew Baxter-Reynolds 2001-2010. All rights reserved.
Contact Us - Terms of Use - Privacy Policy - 4.0.30129.1734