How does one get the type of the dropped object? How can it be added it to a specific struct/list?
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.
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,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With