0

i have a gridview where we give the user the option to move rows, currently only the possibility to move 1 row up and down (on button click and drag/drop).

We need to give the user the possibility to move multiple rows based on selected rows in multiselect, are there any examples of moving multiple rows?

In the current situation we use a database column (sort) on which the grid is sorted, i can use a foreach to update all selected rows by +1 or -1 but how do i handle the unselected rows?

chris
  • 161
  • 2
  • 10

1 Answers1

0

If the standard Drag And Drop Behavior doesn't meet your requirements you can find sample code on how to manually move rows here:

https://github.com/DevExpress-Examples/how-to-reorder-grid-rows-by-drag-and-drop-e764

You need to select an older branch, for example, 7.2.1. Here is corresponding code from this example:

private void MoveRow(int sourceRow, int targetRow)
    {
        if ( sourceRow == targetRow || sourceRow == targetRow + 1 )
            return;

        GridView view = gridView1;
        DataRow row1 = view.GetDataRow(targetRow);
        DataRow row2 = view.GetDataRow(targetRow + 1);
        DataRow dragRow = view.GetDataRow(sourceRow);
        decimal val1 = (decimal)row1[OrderFieldName];
        if ( row2 == null )
            dragRow[OrderFieldName] = val1 + 1;
        else
        {
            decimal val2 = (decimal)row2[OrderFieldName];
            dragRow[OrderFieldName] = (val1 + val2) / 2;
        }
    }

As you can see, you can use decimal instead of int and therefore avoid processing unselected rows at all.

Dmitrii Babich
  • 489
  • 3
  • 4