|
| 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
|
|
|
| |
|
| |
| | |
| |
| 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]
|
|
|
| |
|
|
| |
| |
| 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
|
|
|
| |
|
| |
| |
| 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
|
|
|
| |
|
| |
|
|
|
|
|
|
|
|
|
|
BootFX
Reliable and powerful .NET application framework. |
|
|
|
|
|
|