Reputation: 53
How does one get the type of the dropped object? How can it be added it to a specific struct/list?
Upvotes: 5
Views: 7239
Reputation: 6103
Assuming you control the start of the drag (you're not dragging from another app), it's up to you what the type is. Just make the source and destination code match. In the drag (typically a MouseMove or MouseDown handler):
var dragData = new DataObject(typeof(JobViewModel), job);
DragDrop.DoDragDrop(element, dragData, DragDropEffects.Move);
Begins the drag. And then in the drop (it sounds like you've gotten this far):
var dataObj = e.Data as DataObject;
var dragged = dataObj.GetData(typeof(JobViewModel)) as JobViewModel;
You can also use a String instead of a Type.
Upvotes: 9
Reputation: 3848
Just set the control's AllowDrop property to true. And implement the Drop event on it; you can access the drop information in the event argument.
For the GetData part, you can use this to get specific data types. Here is the file drop for example:
string[] fileNames = (string[])e.Data.GetData(DataFormats.FileDrop, true);
Thanks,
Upvotes: 1