List Box Drag and drop reordering - deletes dragged object if outside listbox

1 Answer 171 Views
ListBox
Stuart Cotts
Top achievements
Rank 1
Stuart Cotts asked on 03 May 2021, 05:52 AM
I am using using Drag and Drop to reorder in a List Box, using the example from the ListBox documentation if I drag outside of the List box the dragged item is deleted from the list box. Any way I can stop this from happening???

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 04 May 2021, 12:09 PM

Hello Stuart,

This is the default behavior of the  base DragDropBehavior class inherited by the ListBoxDragDropBehavior. If the drag/drop action finishes while the mouse is outside of the RadListBox control (over another element that allows drop), the dragged items are removed from the source collection.

To alter this behavior, you can create a custom class deriving from ListBoxDragDropBehavior and override its DragDropCompleted method. There you can implement custom code that executes on drop outside of RadListBox. For example:

public class CustomListBoxDragDropBehavior : ListBoxDragDropBehavior
{
	public override void DragDropCompleted(DragDropState state)
	{
		// do nothing, if you want to avoid removing the dragged items on drag outside of the listbox
		// else, execute custom logic that removes the items. You do this using the following line:
		// RemoveItems(state.SourceItemsSource, state.DraggedItems);
	}
}

Regards,
Martin Ivanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
ListBox
Asked by
Stuart Cotts
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or