Microsoft KB Archive/328590

= BUG: KeyPad PLUS SIGN (+) and MINUS SIGN (-) Do Not Appear in DataGrid Control with Visual Basic .NET =

Article ID: 328590

Article Last Modified on 2/22/2007

-

APPLIES TO


 * Microsoft .NET Framework 1.1
 * Microsoft .NET Framework 1.0 Service Pack 2

-



This article was previously published under Q328590



SYMPTOMS
In the Windows Forms DataGrid control, when you use KeyPad to type PLUS SIGN (+) or MINUS SIGN (-), these symbols do not appear in the DataGrid control.



RESOLUTION
To resolve the problem, you must inherit your own datagrid class from System.Windows.Forms.DataGrid class, and then override the following functions:
 * OnKeyDown

The following code demonstrates this resolution: Public Class MyDataGrid Inherits System.Windows.Forms.DataGrid

Protected Overrides Sub OnKeyDown(ByVal ke As System.Windows.Forms.KeyEventArgs) Select Case ke.KeyCode Case Keys.Add ke = New KeyEventArgs(ke.Modifiers Or Keys.Oemplus) Case Keys.Subtract ke = New KeyEventArgs(ke.Modifiers Or Keys.OemMinus) End Select MyBase.OnKeyDown(ke) MyBase.ProcessGridKey(ke) End Sub

Protected Overrides Function ProcessDialogKey(ByVal keyData As System.Windows.Forms.Keys) As Boolean Select Case keyData Case Keys.Add Return MyBase.ProcessDialogKey(Keys.Oemplus) Case Keys.Subtract Return MyBase.ProcessDialogKey(Keys.OemMinus) Case Else Return MyBase.ProcessDialogKey(keyData) End Select End Function

Protected Overrides Function ProcessKeyPreview(ByRef m As System.Windows.Forms.Message) As Boolean Const WM_KEYDOWN As Integer = &H100 If m.Msg = WM_KEYDOWN Then Dim ke As New KeyEventArgs(CType(m.WParam.ToInt32, Keys) Or ModifierKeys) Select Case ke.KeyCode Case Keys.Add ke = New KeyEventArgs(Keys.Oemplus Or ModifierKeys) Case Keys.Subtract ke = New KeyEventArgs(Keys.OemMinus Or ModifierKeys) End Select Return MyBase.ProcessGridKey(ke) End If       Return MyBase.ProcessKeyPreview(m) End Function End Class



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

