CAN NOT Drag Drop the RadTreeView Nodes

7 posts, 0 answers
  1. tao wang
    tao wang avatar
    3 posts
    Member since:
    Nov 2009

    Posted 23 Nov 2009 Link to this post

    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

  2. tao wang
    tao wang avatar
    3 posts
    Member since:
    Nov 2009

    Posted 24 Nov 2009 Link to this post

    Any one can give me some direction ?
  3. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1512 posts

    Posted 25 Nov 2009 Link to this post

    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.
  4. tao wang
    tao wang avatar
    3 posts
    Member since:
    Nov 2009

    Posted 26 Nov 2009 Link to this post

    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

  5. Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 01 Dec 2009 Link to this post

    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.
  6. Gavin Eyre
    Gavin Eyre avatar
    1 posts
    Member since:
    May 2009

    Posted 01 Mar 2010 Link to this post

    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

  7. Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 04 Mar 2010 Link to this post

    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.
Back to Top