In NET, the DataGridView is a good control. It provides a custom table for inputting and displaying data. if you provide the DataGridView in your program as a way for users to input multi-row data, you may want to redefine the default operation of the enter key.
Assume that when you press the Enter key in the DataGridView, the cursor will move to the cell in which the same column is located (as shown by the Red Arrow), but when multiple rows of data are input, the better way to respond to the Enter key is to move to the first cell in the next row (Blue Arrow ).
To do this, you can use the class derived from the DataGridView: Public class Grid: DataGridView
{
Then override (override) The OnKeyUp protected method: Protected override void OnKeyUp (KeyEventArgs e)
{
If (e. KeyCode = Keys. Enter)
{
Int currentRow = this. CurrentRow. Index;
If (currentRow> = 0)
This. CurrentCell = this. Rows [currentRow]. Cells [0];
}
Base. OnKeyUp (e );
}
Of course, if you want to provide this capability in an existing DataGridView, you can simply sign the KeyUp event and execute the same code in the event handler ).