title: WPF DataGrid - How to make selected row editable on Button click
body: <p>The following DataGrid is set to <code>ReadOnly</code>. But, when <code>Edit Button</code> on a row is clicked I need that row to become editable. How can we achieve this task?</p>
  
  <p>Please note that the Edit button click event is still fired on a ReadOnly grid. Maybe, in this event we need to set <a href="https://docs.microsoft.com/en-us/dotnet/api/system.windows.controls.datagridcell.isediting?view=netcore-3.1" rel="nofollow noreferrer">DataGridCell.IsEditing</a> Property to true for each cell on that row. But I am not able to get the <code>DataGridCell object</code> in the row. Or, there may be some better options.</p>
  
  <pre><code>&lt;Window x:Class="MyTestApp.MainWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          .....
          Title="MainWindow"&gt;
      &lt;Grid&gt;
          &lt;DataGrid x:Name="MyDatagrid" IsReadOnly="True" AutoGenerateColumns="False" SelectionMode="Single"&gt;
              &lt;DataGrid.Columns&gt;
                 &lt;DataGridTemplateColumn Header="Edit"&gt;
                      &lt;DataGridTemplateColumn.CellTemplate&gt;
                          &lt;DataTemplate&gt;
                              &lt;Button x:Name="btnEdit" Content="Edit" Click="btnEdit_Click"&gt;&lt;/Button&gt;
                          &lt;/DataTemplate&gt;
                      &lt;/DataGridTemplateColumn.CellTemplate&gt;
                 &lt;/DataGridTemplateColumn&gt;
                  &lt;DataGridTextColumn Header="ID" Visibility="Collapsed" Binding="{Binding MyClassId}" /&gt;
                  &lt;DataGridTextColumn Header="First Name" Binding="{Binding FirstName}"/&gt;
                  &lt;DataGridTextColumn Header="Last Name" Binding="{Binding LastName}"/&gt;
              &lt;/DataGrid.Columns&gt;
          &lt;/DataGrid&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p><strong>MyClass and other relevant code</strong>:</p>
  
  <pre><code>public class MyClass
  {
      [Key]
      public int MyClassId { get; set; }
      public string FirstName{ get; set; }
      public string LastName{ get; set; }
      .........
      .........
  }
  
  //DataGrid binding to source:
  List&lt;MyClass&gt; lstMyClass = db.MyClass.ToList();
  MyDatagrid.ItemsSource = lstMyClass;
  ............
  .........
  </code></pre>