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

How to customize the default behavior of the RadTreeView

9 Answers 90 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Jorge Alberto
Top achievements
Rank 1
Jorge Alberto asked on 14 Jun 2010, 11:55 PM
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

9 Answers, 1 is accepted

Sort by
0
Accepted
Viktor Tsvetkov
Telerik team
answered on 16 Jun 2010, 01:57 PM
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.
0
Jorge Alberto
Top achievements
Rank 1
answered on 17 Jun 2010, 06:49 AM
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


0
Accepted
Viktor Tsvetkov
Telerik team
answered on 17 Jun 2010, 02:27 PM
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
0
Jorge Alberto
Top achievements
Rank 1
answered on 18 Jun 2010, 07:25 AM
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
0
Tina Stancheva
Telerik team
answered on 21 Jun 2010, 03:13 PM
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
0
Alan
Top achievements
Rank 2
answered on 29 Jun 2010, 02:14 PM
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!
0
Viktor Tsvetkov
Telerik team
answered on 02 Jul 2010, 03:04 PM
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
0
Brandon
Top achievements
Rank 1
answered on 14 May 2012, 08:31 PM
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!
0
Petar Mladenov
Telerik team
answered on 17 May 2012, 08:00 AM
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 >>

Tags
TreeView
Asked by
Jorge Alberto
Top achievements
Rank 1
Answers by
Viktor Tsvetkov
Telerik team
Jorge Alberto
Top achievements
Rank 1
Tina Stancheva
Telerik team
Alan
Top achievements
Rank 2
Brandon
Top achievements
Rank 1
Petar Mladenov
Telerik team
Share this question
or