Good evening to the whole community, my problem is that I have a DataGridView
containing name of dishes, and two buttons one that will select the row above the row that is currently selected (if there is one more above) and another that selects the row below the row that is currently selected (if there is one below). I explain myself better with the image:
currently the second row is selected (meat with carrot), I want to make click
to the first button (ignore the icons, need to change them) select the row above (meat burritos) and the same with the Bottom button, if it stings with the row that is selected, it would go down to select "stew meat".
Currently this is the code for the first button:
int cantidadElementos = dgvPlatillosPedidos.Rows.Count;
DataGridViewSelectedRowCollection dgvColec = dgvPlatillosPedidos.SelectedRows;
int posActual = dgvPlatillosPedidos.CurrentRow.Index;
if (posActual < (cantidadElementos - 1))
{
dgvPlatillosPedidos.Rows[posActual - 1].Selected = true;
}
And this code for the second:
int cantidadElementos = dgvPlatillosPedidos.Rows.Count;
DataGridViewSelectedRowCollection dgvColec = dgvPlatillosPedidos.SelectedRows;
int posActual = dgvPlatillosPedidos.CurrentRow.Index;
if (posActual < (cantidadElementos - 1))
{
dgvPlatillosPedidos.Rows[posActual + 1].Selected = true;
}
But selecting any of them gives me the following error:
I hope you can help me, thank you.