Change drop target on drop end event

6 posts, 0 answers
  1. Roman Gomolko
    Roman Gomolko avatar
    2 posts
    Member since:
    Nov 2009

    Posted 12 Nov 2009 Link to this post

    I have challenge with TreeView and drag and drop feature.

    My goal is to implement next behavior:
    1. User drop one item onto another
    2. System show pop-up like "Enter node title"
    3. Create sub-node to drop target with entered title
    4. Append dropped element to created sub-node,

    What I'm trying to do
    //HierarchyTree.ItemSource = collection of ItemContainer; 
     
    HierarchyTree.DragEnded += HierarchyTree_DragEnded; 
     
    void HierarchyTree_DragEnded(object sender, RadTreeViewDragEndedEventArgs e) { 
                if (e.IsCanceled == true) { 
                    return
                } 
     
                RadTreeViewItem item = e.TargetDropItem; 
                ItemContainer container = item.Item as ItemContainer; 
                if (container != null) { 
                    if (e.DropPosition == DropPosition.Inside) { 
                        Question question = new Question("Condition"); 
                        ItemContainer newContainer = new ItemContainer(question); 
                        newContainer.IsCondition = true
                        newContainer.Children.Add(container); 
                        e.DraggedItems.Clear(); 
                        e.DraggedItems.Add(newContainer); 
                    } 
                } 
            } 
     

    Probably it doesn't have any sense. I hope you can provide me with some directions or partial solution.

    Best Regards, Roman


  2. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1512 posts

    Posted 18 Nov 2009 Link to this post

    Hi Roman,

    I have prepared and attached a sample project demonstrating this functionality. The code is pretty self explanatory, but if you have additional questions, let me know.

    Kind regards,
    Kiril Stanoev
    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.
  3. DevCraft banner
  4. Moises Casusol
    Moises Casusol avatar
    20 posts
    Member since:
    Oct 2009

    Posted 20 Nov 2009 Link to this post

    Hi,
       this is what im looking for, but when i tested the example there is an error or bug i guess. After i drag a first item like "John" with a new header, i drag a second name and try to add this before o after "Jhon" but when i drop it the name is not added to the treeview and it was removed from the list. Im using silverlight 3.0 with RadTreeView Q3 2009.

    Best Regards
    -Lois
  5. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1512 posts

    Posted 23 Nov 2009 Link to this post

    Hello Moises,

    If you take a look at the OnDropInfo event handler, you will see the following if clause:

    if (e.Options.Status == DragStatus.DropComplete && destination is RadTreeView)
    {
    }

    Simply remove destination is RadTreeView and everything should be fine. However, if you still want to make sure you are dropping on the TreeView, extend the if clause so it becomes something like:

    if (e.Options.Status == DragStatus.DropComplete && (destination is RadTreeView || destination is RadTreeViewItem))
    {
    }

    Let me know how this works for you.

    Best wishes,
    Kiril Stanoev
    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.
  6. James
    James avatar
    26 posts
    Member since:
    Oct 2008

    Posted 03 Mar 2010 Link to this post

    Bug? you cannot drop an item into an existing item - which is EMPTY - i.e, has no triangle to expand.

    Repro steps:
    - drag "John" to the left
       - in the popup window, give a name to the folder that will sit on the ROOT (only)  - ex. "Folder1"
    - now expand "Folder1", you will see the "John" node
    - NOW
       - try to drag more items INTO "Folder1" --> you will not see the item
       - try to drag an item to sit UNDER "john" --> item will not get added

    I'm still waiting for telerik response on this behaviour - as I've noticed that when working on our application.
    Anyone else notice that? any suggestions? 
  7. Vladislav
    Admin
    Vladislav avatar
    276 posts

    Posted 09 Mar 2010 Link to this post

    Hi James,

    In order to achieve the desired behavior, you should change the example project.
    In particular you should replace
    treeView1.Items.Add(treeViewItem);
    in private void OnDropInfo(object sender, DragDropEventArgs e)
    with this snippet:
    if ((destination as RadTreeView) != null)
    {
        (destination as RadTreeView).Items.Add(treeViewItem);
    }
    else if ((destination as RadTreeViewItem) != null)
    {
        (destination as RadTreeViewItem).Items.Add(treeViewItem);
    }

    Modifying the example in this way will allow you to drop the dragged item anywhere in the treeview.

    Please let us know if this solution works for you.

    Kind regards,
    Vladislav
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top
DevCraft banner