Special keys handling in DataGridTextBoxColumn

  • Thread starter Thread starter WildGooose
  • Start date Start date
W

WildGooose

I implemented overriding IsInputKey. But, finally realized
that it works on a plain TextBox and not within a TextBox
with a DataGrid.

Dmitrity, susggested me to implement ProcessDialogKey and
ProcessKeyPreview. It works, but not completely.

I implemented ProcessKeyPreview, and it seems to be
capturing only 'Enter' key.
Tab, and directional keys are not being captured. I have
also implemented KeyPress and KeyDown methods to capture
text being edited. But does not seem to completely capture
all special keys.

Implementing ProcessDialogKey does not seem to make any
difference other than being called before
invoking KeyPress and KeyDown methods.

Any suggestions on how to capture Tabs, and directional
keys on a DataGridTextBoxColumn.

Thanks for your suggestions.
-----Original Message-----
Hi,

You will need to override the following methods in the DataGrid itself to
tap into keyboard navigation:

ProcessDialogKey - this method will be called when no cell is being edited
ProcessKeyPreview - this method will be called whe a cell IS being edited to
separate control keys strokes as Tab or Arrows from regular alpha-numeric
keystrokes that should be treated as user input.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Wild Goose said:
Hi all, Need some help here.

I have created my own DataGridTextBoxColumn and
DataGridTableStyle and have bound this to the DataGrid.
I am trying to capture the text changed event on a
DataGridTextBoxColumn. I need an event to be triggered
when the user either edit's text in the textbox, or tabs
on textbox, hits enter key, or presses up/down/right/left
keys.
I tried capturing the LostFocus & Leave events on the
DataGridTextBoxColumn. These events fires only if the
users hits tab on the column. It does not fire on hitting
enter key.
The TextChanged event fires for each character typed,
which probably I think I should be using to check for
integrity of data, but then how do I tell once the user
has finished typing.

Can anyone help me in this context.

Let me know if you still need more explanation.

Thanks
 
Hi,

Maybe this will help.
http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp#q755q

Ken
-------------------
WildGooose said:
I implemented overriding IsInputKey. But, finally realized
that it works on a plain TextBox and not within a TextBox
with a DataGrid.

Dmitrity, susggested me to implement ProcessDialogKey and
ProcessKeyPreview. It works, but not completely.

I implemented ProcessKeyPreview, and it seems to be
capturing only 'Enter' key.
Tab, and directional keys are not being captured. I have
also implemented KeyPress and KeyDown methods to capture
text being edited. But does not seem to completely capture
all special keys.

Implementing ProcessDialogKey does not seem to make any
difference other than being called before
invoking KeyPress and KeyDown methods.

Any suggestions on how to capture Tabs, and directional
keys on a DataGridTextBoxColumn.

Thanks for your suggestions.
-----Original Message-----
Hi,

You will need to override the following methods in the DataGrid itself to
tap into keyboard navigation:

ProcessDialogKey - this method will be called when no cell is being edited
ProcessKeyPreview - this method will be called whe a cell IS being edited to
separate control keys strokes as Tab or Arrows from regular alpha-numeric
keystrokes that should be treated as user input.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Wild Goose said:
Hi all, Need some help here.

I have created my own DataGridTextBoxColumn and
DataGridTableStyle and have bound this to the DataGrid.
I am trying to capture the text changed event on a
DataGridTextBoxColumn. I need an event to be triggered
when the user either edit's text in the textbox, or tabs
on textbox, hits enter key, or presses up/down/right/left
keys.
I tried capturing the LostFocus & Leave events on the
DataGridTextBoxColumn. These events fires only if the
users hits tab on the column. It does not fire on hitting
enter key.
The TextChanged event fires for each character typed,
which probably I think I should be using to check for
integrity of data, but then how do I tell once the user
has finished typing.

Can anyone help me in this context.

Let me know if you still need more explanation.

Thanks
 
Ignore the #Region section, it just came across expanded
when I copied it. I had the same problem you did. This
works. See MS KB Article 320583 - 'How to Trap Keystrokes
in .NET Controls by Using Visual Basic.NET. Also articles
for 6.0 and C#.



Public Class MyDataGrid
Inherits System.Windows.Forms.DataGrid

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form
Designer.
InitializeComponent()

'Add any initialization after the
InitializeComponent() call

End Sub

'UserControl1 overrides dispose to clean up the
component list.
Protected Overloads Overrides Sub Dispose(ByVal
disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the
Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
components = New System.ComponentModel.Container()
End Sub

#End Region

Protected Overrides Function ProcessCmdKey(ByRef msg
As Message, _
ByVal keyData As Keys) As
Boolean
Const WM_KEYDOWN As Integer = &H100
Const WM_SYSKEYDOWN As Integer = &H104

If ((msg.Msg = WM_KEYDOWN) Or (msg.Msg =
WM_SYSKEYDOWN)) Then
Select Case (keyData)
Case Keys.Enter
Me.Visible = False

Case Keys.Down
Me.Parent.Text = "Down Arrow Captured"
Case Keys.Up
Me.Parent.Text = "Up Arrow Captured"
Case Keys.Tab
Me.Parent.Text = "Tab Key Captured"
Case (Keys.Control Or Keys.M)
Me.Parent.Text = "<CTRL> + M Captured"
Case (Keys.Alt Or Keys.Z)
Me.Parent.Text = "<ALT> + Z Captured"
End Select
End If

Return MyBase.ProcessCmdKey(msg, keyData)
End Function


End Class
-----Original Message-----
Hi,

Maybe this will help.
http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp#q755q

Ken
-------------------
WildGooose said:
I implemented overriding IsInputKey. But, finally realized
that it works on a plain TextBox and not within a TextBox
with a DataGrid.

Dmitrity, susggested me to implement ProcessDialogKey and
ProcessKeyPreview. It works, but not completely.

I implemented ProcessKeyPreview, and it seems to be
capturing only 'Enter' key.
Tab, and directional keys are not being captured. I have
also implemented KeyPress and KeyDown methods to capture
text being edited. But does not seem to completely capture
all special keys.

Implementing ProcessDialogKey does not seem to make any
difference other than being called before
invoking KeyPress and KeyDown methods.

Any suggestions on how to capture Tabs, and directional
keys on a DataGridTextBoxColumn.

Thanks for your suggestions.
-----Original Message-----
Hi,

You will need to override the following methods in the DataGrid itself to
tap into keyboard navigation:

ProcessDialogKey - this method will be called when no cell is being edited
ProcessKeyPreview - this method will be called whe a
cell
IS being edited to
separate control keys strokes as Tab or Arrows from regular alpha-numeric
keystrokes that should be treated as user input.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Hi all, Need some help here.

I have created my own DataGridTextBoxColumn and
DataGridTableStyle and have bound this to the DataGrid.
I am trying to capture the text changed event on a
DataGridTextBoxColumn. I need an event to be triggered
when the user either edit's text in the textbox, or tabs
on textbox, hits enter key, or presses up/down/right/left
keys.
I tried capturing the LostFocus & Leave events on the
DataGridTextBoxColumn. These events fires only if the
users hits tab on the column. It does not fire on hitting
enter key.
The TextChanged event fires for each character typed,
which probably I think I should be using to check for
integrity of data, but then how do I tell once the user
has finished typing.

Can anyone help me in this context.

Let me know if you still need more explanation.

Thanks


.
 
Back
Top