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
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:
publicclassCustomListBoxDragDropBehavior : ListBoxDragDropBehavior
{
publicoverridevoidDragDropCompleted(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/.