How to customize the default behavior of the RadTreeView

10 posts, 2 answers
  1. Jorge Alberto
    Jorge Alberto avatar
    38 posts
    Member since:
    Dec 2009

    Posted 14 Jun 2010 Link to this post

    Hello everybody :)

    My scenario is the following: 

    I have a TreeView with services grouped by category just like this:

    Cateogory 1:
    Service 1
    Service 2
    Category 2:
    Service 3
    Service 4:

    And another empty TreeView. The user can drag and drop services from the "services-tree" to the "empty-tree".
    I have set the IsDragDropEnable = true, and the default behavior is great but I want to customize the default behavior of the TreeView to achieve the following:

    1.- When the user drag an drop successfully a service, this service should not be removed from the "service-tree".
    2.- Prevent that the user drop the same service into the "empty-tree" more than once. The "empty-tree" cannot host the same item more than once.
    3.- Allow that the user reorder the services on the "empty-tree", i.e. allow drag and drop for the items of the "empty-tree" before or after it current position but no inside of each other.

    Can you tell me please which events I have to handle to achieve this behavior? If possible I really appreciate if you add some code snippets.  

    Is this possible?
    I hope you can help me.

    Best Regards
    Jorge

  2. Answer
    Viktor Tsvetkov
    Admin
    Viktor Tsvetkov avatar
    382 posts

    Posted 16 Jun 2010 Link to this post

    Hello Jorge,

    I've attached a simple solution to your scenario. Have a look at it and feel free to modify and extend it further. Let us know if you have questions or comments regarding this topic.

    On a side note, I'd like to inform you that we've just released an online tool that allows you to reduce the size of your Silverilght applications. For more information, please visit http://blogs.telerik.com/blogs/posts/10-06-10/telerik_assembly_minifier.aspx

    All the best,
    Viktor Tsvetkov
    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.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Jorge Alberto
    Jorge Alberto avatar
    38 posts
    Member since:
    Dec 2009

    Posted 17 Jun 2010 Link to this post

    Hello Viktor :)

    Thank you so very much for your answer. Your sample project really helped me to understand how to customize the RadTreeView's dragAndDrop default behavior to fit my requirements. 

    Nevertheless, I have a question. You added a handler to the PreviewDragEnded event in order to prevent dropping an item if the e.DropPositon equals DropPosition.Inside, but I have read on RadControlSilverlightCourseware the following:

    "PreviewDragStarted, DragStarted, PreviewDragEnded and DragEnded events all carry over as
    backward compatibility for earlier versions of RadTreeView that had special drag-and-drop logic.
    Now the RadDragAndDropManager is built-in so its best to use the events you learned about in
    the "Drag and Drop" chapter."

    Can I get the same behavior only by writing handlers for the events dragQuery, dropQuery, dragInfo, dropInfo?

    Best Regards
    Jorge


  5. Answer
    Viktor Tsvetkov
    Admin
    Viktor Tsvetkov avatar
    382 posts

    Posted 17 Jun 2010 Link to this post

    Hello Jorge,

    I made a change to the project and send it to you without the PreviewDragEnded method. Let me know how it works for you.

    Kind regards,
    Viktor Tsvetkov
    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
  6. Jorge Alberto
    Jorge Alberto avatar
    38 posts
    Member since:
    Dec 2009

    Posted 18 Jun 2010 Link to this post

    Hello Viktor

    Thanks for answering. It works nice. Now when trying to drop a service inside another the drag cue change and gives a visual feedback, telling the user that is not permitted to drop a service inside another service. Writing a event handler for the PreviewDragEnded event, actually prevent the drop of a service inside another service, but does not provide a visual feedback to the user.

    Best regards
    Jorge
  7. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 21 Jun 2010 Link to this post

    Hello Jorge Alberto,

    I am glad that the example works for you. However, let me just clarify a few things, just in case.

    You are right about the PreviewDragEnded event, canceling the drop operation. This event handler is useful, when you want to cancel adding/removing items from the RadTreeView's ItemsCollection. However, if you want to disable the drop operation on specific items and provide the user with a corresponding feedback, you can set the IsDropAllowed property of  the items to false either in the ItemPrepared() event handler or in the OnDropInfo() event handler or pretty much wherever you need to.

    Another approach would be to handle the OnDropQuery() event and set the QueryResult accordingly as in the previously attached example.

    Further description of the Drag And Drop functionality of the RadTreeView can be found in this article.

    I hope this information will help you choose the best suited approach for your scenario.

    Should you need any further assistance, please do not hesitate to contact us again.

    Greetings,
    Tina Stancheva
    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
  8. Alan
    Alan avatar
    47 posts
    Member since:
    Jun 2009

    Posted 29 Jun 2010 Link to this post

    With the above example project, is there any way to get the red circle to appear when the drop is not allowed?  I tried to follow Tina's suggestions but I'm not able to get it to work.

    I tried using ItemPrepared, but that event doesn't get called until after the item has been dropped.  OnDropQuery already sets e.QueryResult to false, but that doesn't make the red circle appear either.

    Any other suggestions?

    Thanks!
  9. Viktor Tsvetkov
    Admin
    Viktor Tsvetkov avatar
    382 posts

    Posted 02 Jul 2010 Link to this post

    Hi Alan,

    In this case if you want to get the red circle you should set IsDragDropEnabled to true on the treeviews and then add PreviewDragEnded event where to cancel the removing of items from the source treeview. Attached is the modified project. If you have further questions feel free to ask.

    On a side note, I'd like to inform you that we've just released an online tool that allows you to reduce the size of your Silverilght applications. For more information, please visit http://blogs.telerik.com/blogs/posts/10-06-10/telerik_assembly_minifier.aspx

    Sincerely yours,
    Viktor Tsvetkov
    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
  10. Brandon
    Brandon avatar
    10 posts
    Member since:
    May 2012

    Posted 14 May 2012 Link to this post

    Is there some way to allow reordering of nodes that are not in the top level of the RadTreeView structure.  In other words - for this example - to allow the user to re-order the services within the categories on the left-side treeview?

    Thanks!
  11. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 17 May 2012 Link to this post

    Hello Brandon,

    This is a very old post. In order to re-order RadTreeViewItems successfully, you have to make sure that all of the ViewModels collection are ObservableCollections , not Lists. Please let us know if this helps.

    All the best,
    Petar Mladenov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top
UI for WPF is Visual Studio 2017 Ready