We're currently working on the RadTreeView
logic. Up until now it used to work with the old RadDragAndDropManager
. And we're currently migrating this logic to use the new DragDropManager
We've already released most of the changes with the Q1 2013 SP1
release (v. 2013.1.403
) but we added a few new features in the latest internal build as well. We're targeting the Q2 2013
as the official release of the updated DragDrop
logic of the control and we're currently gathering feedback regarding the new features. And we will highly appreciate it if you can download the latest internal build and test your application with it and with the new DragDrop logic.
Now to get straight to your question - if you're using our latest version, then it its best to set the telerik:TreeViewSettings.DragDropExecutionMode
attached property to New
and use the new DragDrop
logic. Then you can think of the RadTreeView DragDrop
logic in the context of the DragDropManager
events and properties. This means that you have a few options to disable the drag operation when a particular item is being dragged:
- You can use data-binding to bind the DragDropManager.AllowCapturedDrag and DragDropManager.AllowDrag attached properties. These two properties define whether any object can be dragged or not. However, in the RadTreeView we have a IsDragDropEnabled property that is responsible for the overall Drag/Drop-enabled state of the control. This is why when you set the IsDragDropEnabled property to True, the control will apply the AllowCapturedDrag and AllowDrag properties to True for all RadTreeViewItems. Unfortunately as this is implemented behind the scenes, you can't have a custom style setting the RadTreeViewItems DragAllowed settings to False at the same time. The Style settings will be overriden by the built-in logic of the control. However, in a data-binding scenario, you can have two different business objects that together define if an item can be dragged or not. This approach should include a property that controls if an item can be dragged at all and another property that should be data-bound to the DragDropManager.AllowCapturedDrag and DragDropManager.AllowDrag attached properties. Once you define these properties, you can use the first one to decide whether or not to update the second one. I demonstrated this approach in a sample solution so that you can have a closer look at it and consider whether it is a good option for you.
- Another option is to handle the ItemPrepared event - when the RadTreeView.ItemsSource collection is populated with business data, the ItemPrepared event is fired for every business object once its RadTreeViewItem container is generated and fully initialized. This makes this event a good place to change the values of the DragDropManager.AllowCapturedDrag and DragDropManager.AllowDrag attached properties.
- The next option is to handle the DragDropManager DragInitialize event handler for the RadTreeView:
sender, DragInitializeEventArgs args)
var options = DragDropPayloadManager.GetDataFromObject(args.Data, TreeViewDragDropOptions.Key)
Once you do that, you can access the dragged RadTreeViewItem
and create custom logic that defines whether to cancel the drag operation.
I hope this information will help you and if you believe that we should provide a better option to implement your requirements, please let us know. As we're still gathering feedback on the DragDrop implementation, your input will be highly appreciated.
the Telerik team