New to Telerik UI for WPFStart a free 30-day trial

Cancel Drop

Updated on Oct 1, 2025

This article demonstrates how to cancel the drop operation. This is useful when you want to forbid the dropping on or the dropping of a particular item when using the RadTreeView control.

To do so, you can subscribe the RadTreeView element to the DragDropManager.Drop event and set the DropAction of the TreeViewDragDropOptions to DropAction.None.

Example 1: Subscribing the control for the Drop event

C#
	DragDropManager.AddDropHandler(this.radTreeView, OnDrop, true);

Example 2: Canceling the drag

C#
	private void OnDrop(object sender, Telerik.Windows.DragDrop.DragEventArgs e)
	{
		TreeViewDragDropOptions options = DragDropPayloadManager.GetDataFromObject(e.Data, TreeViewDragDropOptions.Key) as TreeViewDragDropOptions;
		if (options != null && options.DragSourceItem != null)
		{
			// cancel the drop operation under a certain condition
			options.DropAction = DropAction.None;
		}
	}

Code Example

This section contains a runnable code example showing how to cancel dropping on a specific item.

Example 3: Treeview definition

XAML
	<telerik:RadTreeView x:Name="radTreeView" IsDragDropEnabled="True">
		<telerik:RadTreeViewItem Header="Sport Categories" IsExpanded="True">
			<telerik:RadTreeViewItem Header="Football" IsExpanded="True">
				<telerik:RadTreeViewItem Header="Futsal"/>
				<telerik:RadTreeViewItem Header="Soccer"/>
			</telerik:RadTreeViewItem>
			<telerik:RadTreeViewItem Header="Tennis"/>
			<telerik:RadTreeViewItem Header="Cycling"/>
		</telerik:RadTreeViewItem>
	</telerik:RadTreeView>

Example 4: Subscribing the control for DragInitialize

C#
	DragDropManager.AddDropHandler(this.radTreeView, OnDrop, true);

Example 5: Defining the DragInitialize handler and implementing logic that checks if the item can be dragged

C#
	private void OnDrop(object sender, Telerik.Windows.DragDrop.DragEventArgs e)
	{
		TreeViewDragDropOptions options = DragDropPayloadManager.GetDataFromObject(e.Data, TreeViewDragDropOptions.Key) as TreeViewDragDropOptions;
		if (options != null && options.DragSourceItem != null)
		{
			RadTreeViewItem dropTargetItem = options.DropTargetItem;
			if (dropTargetItem.Header.ToString() == "Football")
			{
				options.DropAction = DropAction.None;
			}
		}
	}

In this case you cannot drop items on the "Football" item.

See Also

In this article
Code ExampleSee Also
Not finding the help you need?
Contact Support