title: DataGrid get selected rows' column values
body: <p>I'm trying to get the values of each column of a selected row in a DataGrid. This is what I have:</p>
  
  <pre><code>private void dataGrid1_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
  {
      DataGrid dg = sender as DataGrid;
      Console.WriteLine(dg.SelectedCells[0].ToString());
  }
  </code></pre>
  
  <p>But this does not work. If I do a <code>SelectedCells.Count</code> then I get the correct number of columns but I cannot seem to actually get the values of these columns in the selected row. I've tried for quite a while with no luck! Here is my XAML:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;Grid&gt;
      &lt;DataGrid CanUserAddRows="True" AutoGenerateColumns="False" Height="200" HorizontalAlignment="Stretch" Margin="12,12,79,0" Name="dataGrid1" VerticalAlignment="Top" Width="389" DataContext="{Binding}" CanUserResizeColumns="False" CanUserResizeRows="False" HorizontalContentAlignment="Stretch" PreviewMouseDoubleClick="dataGrid1_PreviewMouseDoubleClick" CellEditEnding="dataGrid1_CellEditEnding"&gt;
          &lt;DataGrid.Columns&gt;
              &lt;DataGridTextColumn Binding="{Binding  Path=UserID}"
                                  Header="User ID" Width="SizeToHeader" /&gt;
              &lt;DataGridTextColumn Binding="{Binding  Path=UserName}"
                                  Header="User ID" Width="SizeToHeader" /&gt;
          &lt;/DataGrid.Columns&gt;
      &lt;/DataGrid&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p>I would ideally like to access the data through doing something like <code>rowData.UserID</code> but I cannot seem to work it out. There are lots of tutorials and help for using DataGridView but I'm not using this.</p>