Question

I am creating a WPF data grid, and I want to be able to reorder rows by dragging and dropping, like this: I click on a row and drag it up or down. As I do, a marker shows where the row will be dropped if I release the mouse. When I do release the mouse, the dragged row is inserted where indicated by the marker.

Has anyone seen any articles or blog posts that show how to do this? I don't want to re-invent the wheel if I don't have to, and Google isn't turning up anything. Thanks.

Was it helpful?

Solution

Sorry--bad key word choice. Early morning, no coffee...

Turns out there are a number of samples, under "WPF DataGrid Drag and Drop". Here are three:

MSDN Sample
Vincent Sibal's Blog
Philipp Sumi's Blog

OTHER TIPS

I would suggest using the drag and drop behavior called GongSolutions.WPF.DragDrop. It works on any ItemsControl and thus also on DataGrid It allows MVVM style use cases using attached property setters to enable it. You should check out the link for a simple example.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top