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
Well, the grid doesn't have any built in drag and drop functionality for rows. So this must be something in your code. My guess is that you are looping through the rows in order and moving them one at a time. But once you place Row 1, the rows you are dropping onto have changed. So you need to either loop through the rows backward when dropping, or else drop each row at one position down from the previous dropped row.
either way doesnt work. 1st, i make a debug breakpoint to check the value for looping backward. the value are correctly looping from the last to the 1st selected rows. but after the process is done, the grid still shown in reversed way. 2nd, if drop each row at one position down from the previous dropped row, it will be out of index if i drop a row to the last row index.
My code: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 uwg.Rows.Move(Grid.Selected.Rows(i), dropIndex) NextElse For i As Integer = 0 To Grid.Selected.Rows.Count - 1 Grid.Rows.Move(uwg.Selected.Rows(i), dropIndex) NextEnd If
That trick only can solved the problem from dragging the selected rows to an index that is below or after the last selected rows index to prevent it in a reversed order. BUT, if selected altenate rows and dropped in the middle of the selected rows, it still blown.
please assists, thank you.
Perhaps this is an issue with the order in which the rows are selected. I beleive the Selected.Rows collection has a Sort method you can use to sort the selected rows in the order that they appear.
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.