I'm busy writing an Orders application and one of the columns in the DGV is editable so the user can type in the order amount of the product. I'd like to know if there's a way to set focus to a particular cell so that if there's more than one item in the DGV and the user presses the Enter key, the next cell (Order amount) will be selected. The user must just be able to type in another amount without first having to click on the cell. Ive tried a couple of things already but nothing seems to work properly without the user first having to click on the cell to set focus on the cell and begin typing in the order amount.
There's no Cell.Focus() method and even though I've tried
Expand|Select|Wrap|Line Numbers
- DataGridView1.Rows[DataGridView1.CurrentRow.Index].Cells["columnName"].Selected = true;
This is what I have on the DGV's KeyUp event:
Expand|Select|Wrap|Line Numbers
- private void DataGridView1_KeyUp(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- {
- DataGridView1.Rows[DataGridView1.CurrentRow.Index].Cells["columnName"].Selected = true;
- int columnIndex = int.Parse(DataGridView1.Columns["columnName"].Index.ToString().Trim());
- int rowIndex = int.Parse(DataGridView1.Rows[DataGridView1.CurrentRow.Index].ToString().Trim());//.Cells["columnName"].Value.ToString().Trim()) - 1;
- DataGridView1.CurrentCell = DataGridView1[columnIndex, rowIndex];
- DataGridView1.BeginEdit(true);
- }
- }