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

Change drop target on drop end event

5 Answers 110 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Roman Gomolko
Top achievements
Rank 1
Roman Gomolko asked on 12 Nov 2009, 10:47 AM
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


5 Answers, 1 is accepted

Sort by
0
Kiril Stanoev
Telerik team
answered on 18 Nov 2009, 01:31 PM
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.
0
Moises Casusol
Top achievements
Rank 1
answered on 20 Nov 2009, 09:42 PM
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
0
Kiril Stanoev
Telerik team
answered on 23 Nov 2009, 04:04 PM
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.
0
James
Top achievements
Rank 1
answered on 03 Mar 2010, 11:04 PM
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? 
0
Vladislav
Telerik team
answered on 09 Mar 2010, 10:30 AM
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.
Tags
TreeView
Asked by
Roman Gomolko
Top achievements
Rank 1
Answers by
Kiril Stanoev
Telerik team
Moises Casusol
Top achievements
Rank 1
James
Top achievements
Rank 1
Vladislav
Telerik team
Share this question
or