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

Drag and drop onto ListBox item

2 Answers 253 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Georg
Top achievements
Rank 1
Veteran
Georg asked on 11 May 2020, 04:12 PM
I would like to drag a ListBox item and drop it onto another item. In OnDragOver and OnDrop the sender is the ListBox, but I don't see a way to identify the specific item I am dragging over or dropping on. Is there a way to do that?

2 Answers, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 14 May 2020, 10:55 AM

Hello Georg,

To achieve your requirement you can create a custom ListBoxDragDropBehavior and override its CanDrop and Drop methods.

public class CustomDragDropBehavior : ListBoxDragDropBehavior
{
	public override bool CanDrop(DragDropState state)
	{
		var draggedItems = state.DraggedItems;
		var dropPosition = state.DropPosition;
		return base.CanDrop(state);
	}

	public override void Drop(DragDropState state)
	{
		base.Drop(state);
	}
}

If you use DragDropManage to create the drag/drop customization, you can get the dragged item via the OriginalSource property of the event arguments. For the drop target, you will need to implement some code that detects what is the element under the mouse

Can you please try those approaches and let me know if you need further assistance?

Regards,
Martin Ivanov
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Georg
Top achievements
Rank 1
Veteran
answered on 14 May 2020, 05:57 PM
Thanks Martin - I'll give that a try. I had another idea too, which involved rearranging the UI so the drag was to a TreeView instead. I'll try this first though.
Tags
ListBox
Asked by
Georg
Top achievements
Rank 1
Veteran
Answers by
Martin Ivanov
Telerik team
Georg
Top achievements
Rank 1
Veteran
Share this question
or