If you mean changing the selected row index, this should work:
private void button_Click(object sender, EventArgs e) { grid.ClearSelection();
If you want to swap lines (for example, exchange data in the 1st and 3rd lines), select the option:
int currentRowIndex = 0; int newRowIndex = 2; var currentRow = grid.Rows[currentRowIndex]; var rowToReplace = grid.Rows[newRowIndex]; grid.Rows.Remove(currentRow); grid.Rows.Remove(rowToReplace); grid.Rows.Insert(currentRowIndex, rowToReplace); grid.Rows.Insert(newRowIndex, currentRow);
source share