title: Sum Datagrid Column
body: <p>I am looking to sum a column on a simplified datagrid when I add new rows, but I have no idea how to do this.  Can someone tell me how I would go about this?</p>
  
  <p>Thanks for your help as always.</p>
  
  <pre><code>   XAML
     &lt;Grid&gt;
      &lt;DataGrid x:Name="ResultsDataGrid" HorizontalAlignment="Left" Margin="87,41,0,0" VerticalAlignment="Top" Height="134" Width="835" CanUserAddRows="False" CanUserDeleteRows="False" /&gt;
      &lt;Button x:Name="AddResult" Content="Add Row" HorizontalAlignment="Left" Margin="847,179,0,0" VerticalAlignment="Top" Width="75" Click="AddResult_Click"/&gt;
      &lt;TextBox x:Name="noofrows" HorizontalAlignment="Left" Height="19" Margin="813,180,0,0" TextWrapping="Wrap" Text="0" VerticalAlignment="Top" Width="29"/&gt;
      &lt;Label x:Name="label" Content="No. of Rows" HorizontalAlignment="Left" Margin="741,177,0,0" VerticalAlignment="Top"/&gt;
  &lt;/Grid&gt;
  
     c#
     public class AddResultRow
  {
      public string InspectionFee { get; set; }
  }
  
  public partial class MainWindow : Window
  {
      public ObservableCollection&lt;AddResultRow&gt; _items = new ObservableCollection&lt;AddResultRow&gt;();
  
      public MainWindow()
      {
          InitializeComponent();
          ResultsDataGrid.ItemsSource = _items;
      }
  
      private AddResultRow addnewrow()
      {
          return new AddResultRow()
          {
              InspectionFee = ""
          };
      }
  
      public void AddResult_Click(object sender, RoutedEventArgs e)
      {
          _items.Add(addnewrow());
          int rowCount = ResultsDataGrid.Items.Count;
          noofrows.Text = rowCount.ToString();
      }
  }
  </code></pre>