I feel there is a bug in the drag and drop of the ultragrid.
We found that the rows are getting lost in following scenario.
We have a hierarchy displayed in the Ultragrid. When we drag the element we delete the corresponding element in the attached list and add it to the destination row's collection.
We have a two level hierarchy. root node and it has n children [ n should be greater than 4]. These children are siblings of eachother.
steps:
1. drag any (xth) row and drop it on x+1st or x+2nd row. [drag from above to below]
2. x should not be the last or first row.
3. after this step, xth row is lost.
possible cause : we feel that the grid is not handling the indexing of the rows properly.
because this problem doesnt occur when we drag x+1st or x+2nd element to xth element. [ drag from below to above]. Because in this case the index of the destination row is not disturbed by the drag operation.
Hi,
vazeamit said:I feel there is a bug in the drag and drop of the ultragrid.
Since the grid does not have any built-in drag/drop support for rows, I don't see how this could be the result of a bug in the grid.
If there is an error here, it must be an error in the code you are using to move the rows. Can you post the code you are using?
My guess is that you are not adjusting for the fact that once you remove a row (or rows) from the grid, any row below that row will have it's index adjusted downward.
What I would do is keep a reference to the row you want to move to (the row that the user dropped on). Then call the Move method for each row in order and re-get the index of the row where you want to place the rows being dragged each time.
Hi Mike,
Thanks for your reply. Please find attached the demo app I have developed.
When I used the reference to the grid row, it did not have the desired effect. and i observed that the reference starts pointing to a new object.
Thanks,
Amit V.
Hi Amit,
Your code is a bit complicated and I'm afraid I don't have the kind of time it would take to completely debug it for you. But I noticed a few problems with your MoveElements methods.
For example:
//make destination parent of sourcesrcListObject.ManagerId = destListObject.EmployeeId;srcListObject.ManagerName = destListObject.EmployeeName;
This is not big deal, really, but you are setting the EmployeeId here regardless of whether the parent has actually changed. If I drag a row under parent row 0 and I drop it onto another row under parent row 0, you are updating this value and even though it has not changed.
Probably not a problem, but it's an unneccessary update.
After that, you do this:
newParentListObject.Children.Add(srcListObject);OldParentListObject.Children.Remove(srcListObject);
This might be a problem because you are calling the Add before the remove. In some cases, you will be adding the item to the same collection in which it already exists and then removing it. So the row will simply disappear because the Add does nothing and then the remove works. I would call Remove first.
Then you do this:
ugrDestinationRow.Selected = false;ugrDestinationRow.Expanded = true;
This is fine, as long as the destination row is not one of the rows being dragged.
The rest of this code seems okay to me.
vazeamit said:i observed that the reference starts pointing to a new object.
I'm not sure what this means. What row are you referring to? Once you remove the row and re-add it into the data source, then the grid row which used to refer to that object will be destroyed and a new UltraGridRow will be created for it.