I'm using a WinForms DataGridView for entering sales invoice items.
Suppose my grid looks like this:
| Row |
Qty |
Net Rate |
| 1 |
5 |
... |
| -------- |
-------- |
-------- |
| 1 |
5 |
... |
| 2 |
6 |
... |
| 3 |
(new empty row) |
|
If I edit Row 2 and change the quantity from 6 to 12, then press Enter, the DataGridView performs its default behavior and moves the current cell to Row 3 in the Qty column.
What I want instead is:
Finish editing the quantity in the current row.
Run my calculations (amount, discount, profit, etc.).
Keep the focus on the same row.
Move the current cell to the NetRate column of Row 2.
In other words, I want to override the default Enter key navigation so that pressing Enter in the Qty column does not move to the next row, but instead moves to another column in the current row.
What is the recommended way to achieve this in WinForms? Should I handle KeyDown, ProcessCmdKey, CellEndEdit, or another event?
Any example would be appreciated.