title: Datagrid add items to datatable from another window
body: <p>I got a little problem in my program here. I am trying to add items to my datatable and then get it to show on my datagrid. I can do it with a simple code from my main page but I want an external page to send the results to me but I cant find out what I am doing wrong here.</p>
  
  <p><strong>MainWindow</strong></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Windows;
  using System.Windows.Controls;
  using System.Windows.Data;
  using System.Windows.Documents;
  using System.Windows.Input;
  using System.Windows.Media;
  using System.Windows.Media.Imaging;
  using System.Windows.Navigation;
  using System.Windows.Shapes;
  using System.Data;
  
  namespace Træner_Program
  {
  /// &lt;summary&gt;
  /// Interaction logic for MainWindow.xaml
  /// &lt;/summary&gt;
  public partial class MainWindow : Window
  {
      public MainWindow()
      {
          InitializeComponent();
          Display();
      }
  
       public DataTable dt = new DataTable(); 
      public DataTable dtBind = new DataTable(); 
  
      public void Display() 
      { 
          //I create the data in memory 
          //usually the date is get from DataBase and cached in memory to enhance the performance 
          dt = new DataTable();
          dt.Columns.Add("Øvelse");
          dt.Columns.Add("Vægt");
          dt.Columns.Add("Sæt");
          dt.Columns.Add("Gentagelser");
          dt.Columns.Add("Pause");
          dtBind = dt.Copy();
          Binding bind = new Binding();
          bind.Source = dtBind;
          this.dtgPlan.SetBinding(ListView.ItemsSourceProperty, bind); 
      } 
  
      public void AddRow(string Øvelse, string Vægt, string Sæt, string Gentagelser, string Pause)         
      { 
          DataRow dr = dt.NewRow(); 
          dr["Øvelse"] = Øvelse; 
          dr["Vægt"] = Vægt; 
          dr["Sæt"] = Sæt;
          dr["Gentagelser"] = Gentagelser;
          dr["Pause"] = Pause; 
          dt.Rows.Add(dr);
          dtBind = dt.Copy();
          Binding bind = new Binding();
          bind.Source = dtBind;
          this.dtgPlan.SetBinding(ListView.ItemsSourceProperty, bind); 
  
      } 
  
      private void btnGem_Click(object sender, RoutedEventArgs e)
      {
          //this is the working command from mainpage
          //AddRow("Bænkpres", "80", "3", "10", "50");
      }
  
      private void btnTilføj_Click(object sender, RoutedEventArgs e)
      {
          var tilføjØvelse = new Tilføj_Øvelse();
          tilføjØvelse.Show();
  
  
  
      }
  }
  }
  </code></pre>
  
  <p><strong>Add items</strong></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Windows;
  using System.Windows.Controls;
  using System.Windows.Data;
  using System.Windows.Documents;
  using System.Windows.Input;
  using System.Windows.Media;
  using System.Windows.Media.Imaging;
  using System.Windows.Shapes;
  
  namespace Træner_Program
  {
  /// &lt;summary&gt;
  /// Interaction logic for Tilføj_Øvelse.xaml
  /// &lt;/summary&gt;
  public partial class Tilføj_Øvelse : Window
  {
      MainWindow mw = new MainWindow();
  
      public Tilføj_Øvelse()
      {
          InitializeComponent();
      }
  
      private void btnTilføj_Click(object sender, RoutedEventArgs e)
      {
          mw.AddRow("Bænkpres", "80", "3", "10", "50");
          Close();
      }
  
      private void btnAnuller_Click(object sender, RoutedEventArgs e)
      {
          Close();
      }
  }
  }
  </code></pre>