I’m trying to move a row down in a DataGridView and keep it selected.
The code I have works for moving a row up, but when I move it down, the row highlight appears in the correct place, but the triangle marker is still on the previous row and tracing through the code it looks like it still thinks the previous row is selected.
The code is as follows:
int index = dgvIPAddresses.CurrentCell.OwningRow.Index;
DataGridViewRowCollection rows = dgvIPAddresses.Rows;
// remove the next row and add it in front of the selected row.
DataGridViewRow nextRow = rows[index + 1];
nextRow.Frozen = false;
dgvIPAddresses.Rows[index + 1].Selected = true;
Any ideas ?
Thanks in advance,
what you see is the same in WinForms. You also need to change the CurrentRow. While this property is readonly you have to change it by setting the CurrentCell property.
Adding the following code to your sample works as expected:
dataGridView1.CurrentCell = dataGridView1.Rows[index + 1][“Column0”];
(Column0 is just a sample name).
Please login first to submit.