tags:

views:

73

answers:

1

when I am editing a cell and press enter the next row is automatically selected, I want to stay with the current row... I want to happen nothing except the EndEdit.

I have this:

private void dtgProductos_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            dtgProductos[e.ColumnIndex, e.RowIndex].Selected = true; //this line is not working
            var index = dtgProductos.SelectedRows[0].Cells.IndexOf(dtgProductos.SelectedRows[0].Cells[e.ColumnIndex]);
            switch (index)
            {
                case 2:
                    {
                        dtgProductos.SelectedRows[0].Cells[4].Selected = true;
                        dtgProductos.BeginEdit(true);
                    }
                    break;
                case 4:
                    {
                        dtgProductos.SelectedRows[0].Cells[5].Selected = true;
                        dtgProductos.BeginEdit(true);
                    }
                    break;
                case 5:
                    {
                        btnAddProduct.Focus();
                    }
                    break;
                default:
                    break;
            }
        }

so when I edit a row that is not the last one I get this error:

Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function.
+1  A: 

I think you'll need to override ProcessEnterKey to not advance focus to the next row.

Maybe this thread will help.

John at CashCommons
I am unable to find which method to override, can you help me on this?
Luiscencio
now I got it... I left the override method empty but I still got the error =(
Luiscencio
Added a link that I found googling phrase "changing default behavior of enter key datagridview" (because advancing a row is the default behavior).
John at CashCommons