Reputation: 1
I have a datagridview in windows forms, the default behavior when editing values is that after the edition of a cell, when I press enter, the selected row changes to the next
my question is that change column after cell edit and not change row to next
Upvotes: 0
Views: 21
Reputation: 3143
You should handle the dataGridView1_KeyDown
event.
I didn't really tested the code, but I think it's something like this.
private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.Enter)
{
int col = dataGridView1.CurrentCell.ColumnIndex;
int row = dataGridView1.CurrentCell.RowIndex;
dataGridView1.CurrentCell = dataGridView1[col, row];
e.SuppressKeyPress = true;
e.Handled = true;
}
}
Upvotes: 0