title: Get data of specific cell from selected row in DataGrid WPF C#
body: <p>I have a DataGrid which I fill with data from my sql database.
  Now I want to get a specific cell (2nd cell) from the row I selected with a checkbox.</p>
  <p>This is what I have now:
  WPF XAML:</p>
  <pre><code>&lt;DataGrid Name=&quot;myGrid&quot;&gt;
      &lt;DataGrid.Columns&gt;
          &lt;DataGridTemplateColumn&gt;
              &lt;DataGridTemplateColumn.CellTemplate&gt;
                  &lt;DataTemplate&gt;
                      &lt;CheckBox Checked=&quot;CheckBox_Checked&quot;/&gt;
                  &lt;/DataTemplate&gt;
              &lt;/DataGridTemplateColumn.CellTemplate&gt;
          &lt;/DataGridTemplateColumn&gt;
      &lt;DataGridTextColumn Header=&quot;CustomerID&quot; Width=&quot;Auto&quot; Binding=&quot;{Binding CustomerID}&quot;/&gt;
      &lt;DataGridTextColumn Header=&quot;ItemID&quot; Width=&quot;Auto&quot; Binding=&quot;{Binding ItemID}&quot;/&gt;
  &lt;DataGrid&gt;
  </code></pre>
  <p>C# code:</p>
  <pre><code>private void CheckBox_Checked(object sender, RoutedEventArgs e)
      {
          DataGrid row = (DataGrid)myGrid.SelectedItems[1];
          System.Windows.MessageBox.Show(row);
      }
  </code></pre>
  <p>I get a error when running:</p>
  <blockquote>
  <p>System.ArgumentOutOfRangeException</p>
  <p>{&quot;Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index&quot;}</p>
  </blockquote>
  <p>What am I doing wrong? Do I have to use another approach to get the cell I want?</p>