title: In MahApps Metro DataGridCheckBoxColumn how can I programmatically return checkbox values? (and fix extra row)
body: <p>I know this isn't necessarily specific to MahApps Metro DataGridCheckBoxColumns, but I figured that information may help someone answer my question.</p>
  
  <p>I'm trying to do two things with my DataGridCheckBox Column in <a href="http://mahapps.com/" rel="nofollow noreferrer">MahApps Metro</a></p>
  
  <p><strong>1. I would like to have two separate datagrids, and have the ability to return the value in the second column of whichever row is selected</strong></p>
  
  <p>For example, if I had a datagrid that looked like this:</p>
  
  <p><a href="https://i.stack.imgur.com/TYAaV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TYAaV.png" alt="enter image description here"></a></p>
  
  <p>When someone has the checkbox associated with 2 selected, and the checkbox associated with Red selected, I would like a messagebox to show "2 Red".</p>
  
  <p><strong>my .xaml</strong></p>
  
  <pre><code>        &lt;DataGrid Name="numberGrid"
                ItemsSource="{Binding Path=numberGrid}"
                Grid.Row="0"
                AutoGenerateColumns="False"
                    Width="300"
                    Height="auto"&gt;
              &lt;DataGrid.Columns&gt;
  
                  &lt;DataGridCheckBoxColumn ElementStyle="{DynamicResource MetroDataGridCheckBox}"
                                      EditingElementStyle="{DynamicResource MetroDataGridCheckBox}"
                                      Header="Select"
                                      Binding="{Binding RelativeSource={RelativeSource AncestorType=DataGridRow}, Path=IsSelected, Mode=OneWay}"
                                      /&gt;
                  &lt;DataGridTextColumn     Header="Numbers" 
                                      Binding="{Binding Number, Mode=OneWay}"
                                          Width="*"/&gt;
              &lt;/DataGrid.Columns&gt;
          &lt;/DataGrid&gt;
  
  
  
  
          &lt;DataGrid Name="colorGrid"
                ItemsSource="{Binding Path=colorGrid}"
                Grid.Row="0"
                AutoGenerateColumns="False"
                Width="300"&gt;
              &lt;DataGrid.Columns&gt;
                  &lt;DataGridCheckBoxColumn ElementStyle="{DynamicResource MetroDataGridCheckBox}"
                                      EditingElementStyle="{DynamicResource MetroDataGridCheckBox}"
                                      Header="Select"
                                      Binding="{Binding RelativeSource={RelativeSource AncestorType=DataGridRow}, Path=IsSelected, Mode=OneWay}"
                                      /&gt;
                  &lt;DataGridTextColumn     Header="Colors" 
                                      Binding="{Binding Color, Mode=OneWay}"
                                          Width="*"/&gt;
              &lt;/DataGrid.Columns&gt;
          &lt;/DataGrid&gt;
  </code></pre>
  
  <p><strong>my .cs</strong> with the pseudocode of what I think should happen commented out.</p>
  
  <pre><code>    ObservableCollection&lt;MahAppsNumbers&gt; MAnumbers = new ObservableCollection&lt;MahAppsNumbers&gt;
      {
  
          new MahAppsNumbers{Number = "1"},
          new MahAppsNumbers{Number = "2"},
          new MahAppsNumbers{Number = "3"},
          new MahAppsNumbers{Number = "4"}
  
  
      };
  
      public class MahAppsNumbers
      {
          public string Number { set; get; }
      }
  
      ObservableCollection&lt;MahAppsAccents&gt; MAcolors = new ObservableCollection&lt;MahAppsColors&gt;
      {
          new MahAppsColors{Color = "Red"},
          new MahAppsColors{Color = "Orange"},
          new MahAppsColors{Color = "Yellow"},
          new MahAppsColors{Color = "Green"}
      };
  
      public class MahAppsColors
      {
          public string Color { set; get; }
      }
  
  
  
  
      public myWindow()
      {
  
  
  
  
          InitializeComponent();
  
          numberGrid.ItemsSource = MAnumbers;
          colorGrid.ItemsSource = MAcolors;
  
          //Something like this maybe?  I know this isn't a thing you can do
          //string currentNumber = numberGrid.SelectedRow[1]; //to get the second column value
          //string currentColor = colorGrid.SelectedRow[1];
          //MessageBox.Show(currentNumber + currentColor);
  
  
      }
  </code></pre>
  
  <p><strong>2. For bonus points, why do I have an extra row at the end?</strong></p>
  
  <p>I've found TONS of solutions for this, that are all basically the <a href="https://stackoverflow.com/questions/1783839/wpf-datagrid-empty-row-at-bottom">same</a>.  But that doesn't solve my problem.  </p>
  
  <p>Thanks in advance.</p>
  
  <p><strong>Edit 1</strong></p>
  
  <p>Since I want this even to happen every time a box is selected, I'm trying something like this inside of myWindow()</p>
  
  <pre><code>this.numberGrid.SelectedCellsChanged += new SelectedCellsChangedEventHandler(numberGrid_SelectionChanged);
  </code></pre>
  
  <p>and adding a function that hopefully someone can point me in the right direction to fixing.</p>
  
  <pre><code>private void numberGrid_SelectionChanged(object sender, SelectedCellsChangedEventArgs e)
  {
       MessageBox.Show(numberGrid.SelectedItem.ToString());
  }
  </code></pre>