Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using + (plus) and - (minus) keyboard keys as incrementors and decrementors in a DataGridView

On a WinForms application that I am writing in C#, I have a DataGridViewTextBoxColumn with cells holding integer values that I would like the users to be able to increment or decrement using the + and - keys from their keyboards.

I've handled the KeyDown event as it is what I use usually to handle Delete keys, etc, but it isn't working for Plus and Minus keys as pressing them causes the Cell to go in Edit-mode, and the KeyDown event is never fired for those keys as a result. Same for the KeyPress event

Actually, it is fired if I set the cells to readonly, but I am not happy with this solution as it would force me to set the property from true to false in several areas of my code and could quickly become messy.

What would please be the best way to achieve this?

Thanks.

like image 292
Kharlos Dominguez Avatar asked Aug 25 '10 15:08

Kharlos Dominguez


1 Answers

Have you tried with this:

instead of using this: Keys.OemMinus use this: Keys.Subtract

and instead of using this: Keys.Oemplus use this: Keys.Add

like image 117
Tomko Avatar answered Nov 11 '22 21:11

Tomko