Home Forums WinForms controls Xceed Grid for WinForms Move selected rows up & down Reply To: Move selected rows up & down

User (Old forums)
Member
Post count: 23064

The SwapRows(currentRow, previousRow); method taken from your grid samples looks like this:

private void SwapRows(CellRow one, CellRow two)

{

    for (int i = 0; i < one.Cells.Count; i++)

    {

        object pivot = one.Cells[ i ].Value;

        one.Cells[ i ].Value = two.Cells[ i ].Value;

        two.Cells[ i ].Value = pivot;

    }

}

So indexes don’t change, just values in cells one by one, as I understand.

How can I access all selected rows onbuttonclick, keep them in index array and swap one by one? Is it good idea, cos 

foreach (Row selectedRow in gridControl1.SelectedRows) {…} looks simple but throws InvalidOperationException if selection changes inside {…}.

I’m using unbound grid.

Imported from legacy forums. Posted by fluxay (had 676 views)