Hi! I'm trying to add functionality to a XamGrid to reorder the rows by dragging one and inserting it above or below another row when releasing the mouse button. Are there any examples of how to accomplish this? I did some searching and couldn't find anything too substantial on doing this with rows (plenty on columns).
Hello Eric,
Similar question was discussed on the following forum thread:
https://ko.infragistics.com/community/forums/f/ultimate-ui-for-wpf/94002/simple-drag-and-drop-beahvior-on-wpf-xamgrid
You can download and test Andrew's sample applicaiton(XamGridDragDropCase.zip).
Let me know if you have any questions.
Sincerely,ZhivkoAssociate Software Developer
Thanks for the response! I've got the example up and running, but it only shows how to drag rows from a grid to a DragDropManager.DropTarget.
Is there a way to make each row a drop target so I can grab the index of where it's being dropped, perform an insert into the grid at that index, and then delete the dragged row? Or would I need to make a column that has a drop target inside of it?
I found a similar problem to mine, but I don't quite understand where to put the code that was accepted in the second to last reply:
https://ko.infragistics.com/community/forums/f/retired-products-and-controls/71854/drop-onto-a-row-in-xamgrid
DropTarget dropTarget = DragDropManager.GetDropTarget(cell.Row.Control);
if (dropTarget == null)
{
dropTarget = new DropTarget() { IsDropTarget = true };
DragDropManager.SetDropTarget(cell.Row.Control, dropTarget);
}
Where would I put this code?
On another note, how do I set the drag cursor to be a custom cursor instead of the X and the hand?
You can access the underlying object of the CellControl, which is the DropTarget in your scenario and remove it from the ItemSource by using ObservableCollection's Remove method, for example:
private void CustomXamGrid_RowDrop(object sender, RowDragDropEventArgs e) { Grid g = e.DragDropEventArgs.DropTarget as Grid; CellControl CC = Utilities.GetAncestorFromType((DependencyObject)g, typeof(CellControl), false) as CellControl; SampleData SD = e.DragSource.DataObject as SampleData; int rowIndex = CC.Cell.Row.Index; VM.Data.Remove(SD); VM.Data.Insert(rowIndex, SD); //Remove the DropTarget item VM.Data.Remove(CC.DataContext as SampleData); }
//Remove the DropTarget item VM.Data.Remove(CC.DataContext as SampleData);
I have modified and reattached Andrew's sample application.