Hi,
Can anyone help me out for this issue, I tried to drag and drop multiple selected rows to a different row position within same band/grid, the rows dropped correctly to the specified index but it changes the order of the selected rows in a reversed order.
That happened only when the dropped index is greater than the 1st selected rows index or the rows are selected in an alternate manner.
Example:
Row 1 - selected
Row 2
Row 3 - selected
Drop selected Row1 and Row3 into index Row 2. it became
Row3
Row 1
Any idea ?
Thanks
The code I posted here only applies when you are moving rows within the same rows collection. If you are trying to move rows from one collection to another, then the Rows.Move method would not work, in any case.
This doesnt work if we have a hierarchy.
indices are meesed up.
thanks a lot, i think it's working fine now, but i need to add a trick that to allow the drop at the very last row.
If DropIndex < 0 Then
DropIndex = Grid.Rows.Count
End If
Okay, so it looks like your code is quite wisely accounting for the fact that the indices will change when you move a row down, but not when you move a row up. But you are only accounting for this based on the last item in the list. So in this case, you are moving one item up and one item down. In fact, in a case like this, Item 8 really would not move at all, since it is already directly above 9. You really only need to move item 10.
So I think you need to do something like this:
If dropIndex >= 0 Then Grid.Selected.Rows.Sort() 'If Grid.Selected.Rows(Grid.Selected.Rows.Count - 1).Index > dropIndex Then ' For i As Integer = Grid.Selected.Rows.Count - 1 To 0 Step -1 ' Grid.Rows.Move(Grid.Selected.Rows(i), dropIndex) ' Next 'Else ' For i As Integer = 0 To Grid.Selected.Rows.Count - 1 ' Grid.Rows.Move(Grid.Selected.Rows(i), dropIndex) ' Next 'End If For i As Integer = Grid.Selected.Rows.Count - 1 To 0 Step -1 If (Grid.Selected.Rows(i).Index < dropIndex) Then dropIndex -= 1 End If Grid.Rows.Move(Grid.Selected.Rows(i), dropIndex) Next End If
referred to my previous post, order will be messed up if try this out:-
select alternate Row 8 and 10. Drag and Drop to Row 9.
It became
10
8
9
Correct dropped should be
if select row 10 then 8, i got the correct result. I m really not sure what is going on.
Thanks for helping.