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

Moving a node beneath another node

1 Answer 53 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Bob Jones
Top achievements
Rank 1
Bob Jones asked on 17 Oct 2009, 05:46 PM
I have a treeview that contains folders that can contain other folders and documents. The databinding is handled by a C# class that returns a dataview and it displays correctly. When I drag a folder or document to another folder, the source node appears after the destination node rather than beneath it. I need it to appear beneath. For example,

-Folder A
---Document X
-Folder B
---Folder C

When I drag X to B it winds up displaying like this:
-Folder A
-Folder B
---Folder C
-Document X

What I want is this:
-Folder A
-Folder B
---Folder C
---Document X

Here is my code:
        SourceNode.Owner.Nodes.Remove(SourceNode);  
        if (DestNode.Level == 0)  
        {  
            DestNode.Nodes.Insert(0, SourceNode);  
        }  
        else  
        {  
            switch (e.DropPosition)  
            {  
                case RadTreeViewDropPosition.Over:  
                case RadTreeViewDropPosition.Below:  
                    DestNode.InsertAfter(SourceNode);  
                    SourceNode.IsDescendantOf(DestNode);  
                    break;  
                case RadTreeViewDropPosition.Above:  
                    DestNode.InsertBefore(SourceNode);  
 
                    break;  
            }  
        }  
 

The line "SourceNode.IsDecendentOf(DestNode)" seems to have no effect.

Thanks for your help. YOu guys are awesome.

1 Answer, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 20 Oct 2009, 02:30 PM
Hi Bob,

You should use 'Over'  RadTreeViewDrop position as it's demonstrated in our online demo here:

case RadTreeViewDropPosition.Over:
   // child
   if (!sourceNode.IsAncestorOf(destNode))
   {
     destNode.Nodes.Add(sourceNode);
   }
   break;

Kind regards,
Yana
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
Bob Jones
Top achievements
Rank 1
Answers by
Yana
Telerik team
Share this question
or