Trap Keys from DataGrid

G

Guest

I'm using C# on a Windows Form with a datagrid.

I want to trap when a user hits ENTER (or Tab on the last column) so that I can auto add a new row and prepopulate with default values from the previous row. It not be assumed that column values were actually changed on the current row.

I have trapped the PreProcessMessage event on the grid, but that doesn't fire if a column in the grid has focus.

I have tried to trap the keyCode in the Column_Changed event, but it says it is out of scope.

Basically, this is the psuedocode:

User is on row X of a datagrid and wants to add a new line so they hit ENTER
The app needs to add a new row to the datatable and set default values based on the previous row.
The app needs to set the cursor to the first field on the new row.

Any assistance is appreciated.

Larry
 
D

Dmitriy Lapshin [C# / .NET MVP]

Larry,

The three overrides you'll most likely need:

ProcessDialogKey - captures most keystrokes when the grid is not in the
edit mode
ProcessKeyPreview - captures most keystrokes when a cell is being edited
ProcessCmdKey - captures some special keystrokes such as the Del key.

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

Larry said:
I'm using C# on a Windows Form with a datagrid.

I want to trap when a user hits ENTER (or Tab on the last column) so that
I can auto add a new row and prepopulate with default values from the
previous row. It not be assumed that column values were actually changed on
the current row.
I have trapped the PreProcessMessage event on the grid, but that doesn't
fire if a column in the grid has focus.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top