I have Datagrid WPF and I am implementing drag and drop functions.
There is a list of βfilesβ in the datagrid, and the user can drag them and copy the file to the desktop.
This is done as follows:
string[] files = new String[myDataGrid.SelectedItems.Count]; int ix = 0; foreach (object nextSel in myDataGrid.SelectedItems) { files[ix] = ((Song)nextSel).FileLocation; ++ix; } string dataFormat = DataFormats.FileDrop; DataObject dataObject = new DataObject(dataFormat, files); DragDrop.DoDragDrop(this.myDataGrid, dataObject, DragDropEffects.Copy);
I have two questions:
1. When I want to drag a few elements - this is a problem, because after I select a pair and start clicking on it to start the drag, which will be selected, and the rest of the elements will be canceled. I tried the solution given here , but for some reason it does not work.
2. I want to remove the dragged item from the datagrid after copying it. The problem is that I donβt know how to check if the file was copied or the user simply dragged it onto the screen without copying it.
Hope you can help me solve these problems. Thanks!
source share