Numpad plus/minus keys won't work in datagrid

  • Thread starter Thread starter Tomas R
  • Start date Start date
T

Tomas R

Really weird. The ordinary plus/minus works, but not the ones on the
numpad?!

What I've bound to the datagrid is a DataView with a few columns having
numeric values with datatype Int32. (Comming from an SQL Server). The column
have a DataGridTextBoxColumn of course, and I found somewhere on the net
someone saying you could specify TextBox.Multiline = true on the
DataGridTextBoxColumn, but it already is and surely wont fix the problem.
Another place mentioning the problem is on
http://www.dotnet247.com/247reference/msgs/26/133742.aspx, but that
workaround was a little to complicated I believe.
Are the numpad really supposed to work(or NOT work) like this or is it a
serious bug?



Thanks for any responses!

/Tomas R
 
Yes, there are some problems with the keyboard in DataGrid.
As I know Microsoft uses a special textbox in the DataGrid that overrides
the WndProc and filter some keyboard events.
Maybe that is the problem.

Hope this helps
Dan Cimpoiesu
 
Here's a solution:

override the ProcessKeyPreview method in a control inherited from the
DataGrid and add the following code:

if (msg.Msg == 0x100)
{
Keys keyPressed = Keys.KeyCode & (Keys)msg.WParam.ToInt32() ;

if (ModifierKeys == Keys.None && (Keys.Add == keyPressed ||
Keys.Subtract == keyPressed))
{
return false;
}
}
return base.ProcessKeyPreview(ref msg);

You might also need to add similar code to the ProcessCmdKey and
ProcessDialogKey methods.
 
Hmmm, I've spent about 5 hours trying to reslove this issue and I now
finally have a solution. Thanks Dmitriy for pointing me in the right
direction! Here's what worked for me:

public class LODataGrid : DataGrid

{

protected override bool ProcessDialogKey( Keys keyData )

{

//return true if the key should be processed; otherwise, false.

if( (Keys.Add == keyData || Keys.Subtract == keyData) )

{

return false; //Do NOT process this anymore

}

return base.ProcessDialogKey( keyData );

}

}

/Tomas R

Dmitriy Lapshin said:
Here's a solution:

override the ProcessKeyPreview method in a control inherited from the
DataGrid and add the following code:

if (msg.Msg == 0x100)
{
Keys keyPressed = Keys.KeyCode & (Keys)msg.WParam.ToInt32() ;

if (ModifierKeys == Keys.None && (Keys.Add == keyPressed ||
Keys.Subtract == keyPressed))
{
return false;
}
}
return base.ProcessKeyPreview(ref msg);

You might also need to add similar code to the ProcessCmdKey and
ProcessDialogKey methods.

--
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

Tomas R said:
Really weird. The ordinary plus/minus works, but not the ones on the
numpad?!

What I've bound to the datagrid is a DataView with a few columns having
numeric values with datatype Int32. (Comming from an SQL Server). The column
have a DataGridTextBoxColumn of course, and I found somewhere on the net
someone saying you could specify TextBox.Multiline = true on the
DataGridTextBoxColumn, but it already is and surely wont fix the problem.
Another place mentioning the problem is on
http://www.dotnet247.com/247reference/msgs/26/133742.aspx, but that
workaround was a little to complicated I believe.
Are the numpad really supposed to work(or NOT work) like this or is it a
serious bug?



Thanks for any responses!

/Tomas R
 
Back
Top