title: WPF DataGrid: Reordering and Editing Rows with GongSolutions.WPF.DragDrop
body: <p>I'm using GongSolutions.WPF.DragDrop. What I want is to load a List into a DataGrid, be able to add rows, delete rows, edit rows, and drag drop reorder rows. Then read every item from the list in the new order back into a database.</p>
  <p>When I give an item source to a DataGrid, I can't drag drop reorder the rows.</p>
  <p>If I add the items through DataGrid.Items.Add to the DataGrid, I can't edit the rows.</p>
  <p>Source Code;
  MainWindow.xaml</p>
  <pre><code>&lt;Window
      x:Class=&quot;WPFDragDropControls.MainWindow&quot;
      xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
      xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
      xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot;
      xmlns:dd=&quot;urn:gong-wpf-dragdrop&quot;
      xmlns:local=&quot;clr-namespace:WPFDragDropControls&quot;
      xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;
      Title=&quot;MainWindow&quot;
      Width=&quot;800&quot;
      Height=&quot;450&quot;
      Loaded=&quot;Window_Loaded&quot;
      mc:Ignorable=&quot;d&quot;&gt;
      &lt;Grid&gt;
          &lt;DataGrid
              Name=&quot;DataGrid_DD_Test&quot;
              dd:DragDrop.IsDragSource=&quot;True&quot;
              dd:DragDrop.IsDropTarget=&quot;True&quot;
              AutoGenerateColumns=&quot;False&quot;
              CanUserAddRows=&quot;True&quot;
              CanUserDeleteRows=&quot;True&quot;&gt;
              &lt;DataGrid.Columns&gt;
                  &lt;DataGridTextColumn
                      Binding=&quot;{Binding ColumnName}&quot;
                      Header=&quot;ColumnName&quot;
                      IsReadOnly=&quot;False&quot; /&gt;
                  &lt;DataGridTextColumn
                      Binding=&quot;{Binding SystemName}&quot;
                      Header=&quot;SystemName&quot;
                      IsReadOnly=&quot;False&quot; /&gt;
                  &lt;DataGridTextColumn
                      Width=&quot;*&quot;
                      Binding=&quot;{Binding Format}&quot;
                      Header=&quot;Format&quot;
                      IsReadOnly=&quot;False&quot; /&gt;
              &lt;/DataGrid.Columns&gt;
          &lt;/DataGrid&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  <p>MainWindow.xaml.cs</p>
  <pre><code>using System.Collections.Generic;
  using System.Windows;
  
  namespace WPFDragDropControls{
      /// &lt;summary&gt;
      /// Interaction logic for MainWindow.xaml
      /// &lt;/summary&gt;
      public partial class MainWindow : Window
      {
          public MainWindow()
          {
              InitializeComponent();
          }
  
          private void Window_Loaded(object sender, RoutedEventArgs e)
          {
              List&lt;TestItems&gt; TestCollection = new();
  
              TestCollection.Add(new TestItems() { ColumnName = &quot;EmployerSig&quot;, SystemName = &quot;Form9061_1a&quot;, Format = &quot;trim[32]&quot; });
              TestCollection.Add(new TestItems() { ColumnName = &quot;StartDate&quot;, SystemName = &quot;Form9061_6a&quot;, Format = &quot;dt:yyyyMMdd&quot; });
              TestCollection.Add(new TestItems() { ColumnName = &quot;State&quot;, SystemName = &quot;Form9061_4ga&quot;, Format = &quot;trim[2]&quot; });
  
              DataGrid_DD_Test.ItemsSource = TestCollection;
  
              //DataGrid_DD_Test.Items.Add(new TestItems() { ColumnName = &quot;StartDate&quot;, SystemName = &quot;Form9061_6a&quot;, Format = &quot;dt:yyyyMMdd&quot; });
              //DataGrid_DD_Test.Items.Add(new TestItems() { ColumnName = &quot;State&quot;, SystemName = &quot;Form9061_4ga&quot;, Format = &quot;trim[2]&quot; });
              //DataGrid_DD_Test.Items.Add(new TestItems() { ColumnName = &quot;EmployerSig&quot;, SystemName = &quot;Form9061_1a&quot;, Format = &quot;trim[32]&quot; });
          }
  
          class TestItems
          {
              public string ColumnName { get; set; }
              public string SystemName { get; set; }
              public string Format { get; set; }
          }
      }
  }
  </code></pre>
  <p>How can I have my cake and eat it too?</p>