This is a migrated thread and some comments may be shown as answers.

Drag/Drop problem/bug

5 Answers 114 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
xiasma2
Top achievements
Rank 1
xiasma2 asked on 28 Jan 2009, 01:44 PM
Hi.
I have TreeView like:
A
  AA
  AA
B
  BB
  BB
C
  CC
  ...
Drag/drop is only allowed inside of its group. Ex: AA can be moved anywhere inside A group, BB can be moved anywhere inside B group. Initialy i was stopping drop using previewDragEnded. It worked only in situations when drop position was "inside". If drop position was "after" or "before" RadTreeViewDragEndedEventArgs e.TargetDropItem was always null even though if I check TreeView.TargetDropItem was set correctly (I guess it is a bug? ). I couldnt check it cause TreeView.TargetDropItem is not accesible from code.
My current approach is traverse the tree and set IsDropAllowed property on every item. The problem here are elements whose drop position is "after" or "before" which I try to drop after or before root elements (A, B, C). These root elements doesn't have parent elemnent so I don't see any way to set there IsDropAllowed . So behaviour I have now is: after I drag AA after B I got:
B
   BB
   BB
   AA
I thought about adding additional root element and add current root elements to him but in this case I would have to hide (don't display) the new root element otherwise I would have the same problem as before.

Any help or suggestions would be appreciated.

Best Regards,
Jarek (Xiasma)


5 Answers, 1 is accepted

Sort by
0
Boyan
Telerik team
answered on 29 Jan 2009, 04:16 PM
Hi Jarek,

We tested the issue and  the PreviewDragEnded event  always returned null for the TargetDropItem when the item was dropped before or after the target node.  We apologize for the inconvenience. This will be fixed with the next release- Q1 which is planned around the end of February. I updated your Telerik points. For now as a workaround you can use DropPosition for your needs.

Sincerely yours,
Boyan
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
xiasma2
Top achievements
Rank 1
answered on 29 Jan 2009, 04:53 PM
Ok, so is there any way to make impossible moving TreeViewItems before or after root item? As I mentioned before it looks like in this case you are checking for parents' IsDropAllowed property, but root elements doesn't have parent on which I could set IsDropAllowed. So this way I can move any elements after of before root elements.
Best Regards,
Jarek
0
Tihomir Petkov
Telerik team
answered on 30 Jan 2009, 08:39 AM
Hello Jarek,

As Boyan said, we will fix the bug for our Q1 release. Until then, the only workaround I can think of is the following: in the PreviewDragEnded handler you store the position of the dragged element in the tree hierarchy and then in the DragEnded handler you check the new level of the item - if it's 0 you move it back to its old position. However, this is a very ugly solution and I wouldn't recommend it unless you need it urgently.

Best wishes,
Tihomir Petkov
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Meliton Tienda
Top achievements
Rank 1
answered on 27 Oct 2009, 09:57 PM
Hello.

I`m traying to use the drag-drop treeview, and i have a question.

How can I drag and drop treeviewItem between 2 treeviews, and the drag Item not delete in the source treeview.
but the Treeview Item add in the Target Treeview?

Thanks for your help...




0
Bobi
Telerik team
answered on 30 Oct 2009, 04:37 PM
Hello Meliton Tienda,

You can register for the PreviewDragEnded event of the TreeView and handle it. Then the default action on drop will not happen and the item will not be removed from the TreeView.

Please note that in this case you should be careful not to get two same items (same reference) in one ItemsControl because then it will stop working correctly.

Here is the code for it:

treeView.PreviewDragEnded += new RadTreeViewDragEndedEventHandler(treeView_PreviewDragEnded);

And the handler itself:

void allProductsView_PreviewDragEnded(object sender, RadTreeViewDragEndedEventArgs e)
{
    var treeViewItemDestination = e.TargetDropItem;
    //We want to cancel removing the item only if it is dropped outside the current TreeView.
    if (treeViewItemDestination == null || treeViewItemDestination.ParentTreeView != sender)
    {
        e.Handled = true;
    }
}

Hopefully this will help you,

Greetings,
Boryana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
TreeView
Asked by
xiasma2
Top achievements
Rank 1
Answers by
Boyan
Telerik team
xiasma2
Top achievements
Rank 1
Tihomir Petkov
Telerik team
Meliton Tienda
Top achievements
Rank 1
Bobi
Telerik team
Share this question
or