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

CAN NOT Drag Drop the RadTreeView Nodes

6 Answers 186 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
tao wang
Top achievements
Rank 1
tao wang asked on 24 Nov 2009, 02:55 AM

Hi 

Thanks for this useful control, I have met a weired thing while I m using the treeview control on drag/drop function, it works on a new test solution with binding Datasource, but once I do exactly the same method to bind this treeview into my existing project solution, it always show the little "stop" icon whenever you wanna drag/drop a node into another node, which means it doesnt work on my own project solution on the drag/drop, But I build a new testing project solution, it works on the same way I used in my own project solution, Thats really weired, I dont know whats going on for this, 

Furthermore, I wonder how ya change the display order when you have bind the DataSource into treeview which the DataSource does have a display order Id field? I saw there is a Databinding example in the demo, but it doesnt allow you to drag/drop to change the display order.

I am online to be looking forward your valuable reply.

Thank you for any helps

Regards

Eddie

6 Answers, 1 is accepted

Sort by
0
tao wang
Top achievements
Rank 1
answered on 24 Nov 2009, 09:17 AM
Any one can give me some direction ?
0
Kiril Stanoev
Telerik team
answered on 25 Nov 2009, 04:00 PM
Hi Tao,

It is really strange that you experience this issue. I am not really sure what causes your problem. Is it possible for you to send us your project so that we can see what causes drag&drop not to work? From the information you have given us is not clear where the problem comes from, so if you send us a sample project reproducing the issue, we will be better able to assist you.

"Furthermore, I wonder how ya change the display order when you have bind the DataSource into treeview which the DataSource does have a display order Id field?"
In most of the cases, we bind the treeview to an ObservableCollection. This collection internally takes care of reordering the items when they are drag/dropped.

Greetings,
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
tao wang
Top achievements
Rank 1
answered on 27 Nov 2009, 02:33 AM

Hi

Thank you for your valuable reply, In fact I am not able to attach my project as it is a huge business application, can ya give me any suggestions that perhaps shows me some ideas?

for the ObservableCollection(T) Class, are you trying to tell me using the orderby() method? and once drag/drop happens which will trigger the event that make another orderby()?

Regards

Eddie

0
Miroslav
Telerik team
answered on 01 Dec 2009, 02:24 PM
Hi Tao,

The TreeViewDragDrop expects the ItemsSource of the TreeView and all its items will be an IList. If it is anything else (an IEnumerable or ICollection), inserting an item in the middle of the collection is not supported because these interfaces do not have and Insert() method.

It is quite possible that the data source that the TreeView is bound to is an IEnumerable.

Another possible issue is that the Children collection of the items are not initialized yet. The TreeView will not automatically create Children collections for the ViewModel items it is bound to. This is why the items collections of the items you are binding to need to be initialized at least to an empty collection.

Unfortunately there is no easy way to sort the items of a TreeView. If you use the OrderBy() extension method on a collection the result will be an IEnumerable and drag-drop will not work. You will need to handle the DragDrop events and implement custom logic for inserting an item in an IEnumeravle collection.

Since there is no built-in sorting, custom sorting has to be implemented for the data items.

Could you provide some more information so that we can help you further:

- How do you populate the TreeView?
- How do you implementing sorting of the data?
- Is the result of the sorting an IEnumerable? 

We can help you with handling the DragDrop events if the ItemsSource is an IEnumerable, but could you check this first?

Greetings,
Miroslav
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
Gavin Eyre
Top achievements
Rank 1
answered on 01 Mar 2010, 04:55 PM
Miroslav :

Would you please help me with handling the DragDrop events if the ItemsSource is an IEnumerable?
I used RIA service with the Telerik RadTreeView for Silverlight . I do try to cast the IEnumerable<T> to IList<T> and bind the treeview's datasource to IList<T>, but still I can not drop a node.

I know I may need to do something in the PreviewDragEnded event,

       IList<LuOrganizationXml> m_orgList;

        void RadTreeViewOrganization_PreviewDragEnded(object sender, RadTreeViewDragEndedEventArgs e)
        {
                 e.Handled = true;

                m_orgList[0].Children.First().Children.Add(new LuOrganizationXml()
               {
                    Id = 15,
                    ParentId = 2,
                    DisplayValue = "new"
                 });

                RadTreeViewOrganization.ItemsSource = null;
               RadTreeViewOrganization.ItemsSource = m_orgList;
            }

           But I do not want to search the tree, find the node, then add a new node.

           How can I use the

              e.TargetDropItem
              e.DraggedElement
             e.DropPosition
    to implement drag and drop if the ItemsSource is an IEnumerable?

           This is all IEnumerable now, so it looks like I can not do anything with them.
            RadTreeViewItem treeViewItem = e.TargetDropItem;
            RadTreeViewItem treeViewItem = e.DraggedItems as RadTreeViewItem;

Thanks a lot.

Please cc your answers to dyang26@yahoo.com too.

Donna Jiang

0
Miroslav
Telerik team
answered on 04 Mar 2010, 04:04 PM
Hello Gavin Eyre,

It is not needed to handled any other events if the ItemsSource and the children collections of the items are ObservableCollection<T>. Can the code for the ViewModels (the items that you bind to) and the code where you set the ItemsSource or DataContext of the TreeView.

My suggestion will be to refactor the code so that only ObservableCollections are provided to the TreeView. Normally the Ria services will generate osberable collections.

More important here is how you build the hierarchy of items, can you provide this code as well?

Regards,
Miroslav
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
tao wang
Top achievements
Rank 1
Answers by
tao wang
Top achievements
Rank 1
Kiril Stanoev
Telerik team
Miroslav
Telerik team
Gavin Eyre
Top achievements
Rank 1
Share this question
or