title: how to add text from textboxes and add it to datagrid using MVVM Wpf
body: <p>how to add text from textboxes and add it to datagrid using MVVM Wpf?</p>
  
  <p>Code:</p>
  
  <pre><code>public class GtlS4Model : INotifyPropertyChanged
  {
      private Double sNo;
      private Double deliveryNo;
      private Double srNo;
      private Double custPartNo;
      private Double binS4Label;
      private Double masterData;
  
      public double SNo
      {
          get
          {
              return sNo;
          }
  
          set
          {
              sNo = value;
              OnPropertyChanged( "SNo");
          }
      }
  
      public double DeliveryNo
      {
          get
          {
              return deliveryNo;
          }
  
          set
          {
              deliveryNo = value;
              OnPropertyChanged( "Delivery_No");
          }
      }
  
      public double SrNo
      {
          get
          {
              return srNo;
          }
  
          set
          {
              srNo = value;
              OnPropertyChanged( "SrNo");
          }
      }
  
      public double CustPartNo
      {
          get
          {
              return custPartNo;
          }
  
          set
          {
              custPartNo = value;
              OnPropertyChanged("CustPartNo");
          }
      }
  
      public double BinS4Label
      {
          get
          {
              return binS4Label;
          }
  
          set
          {
              binS4Label = value;
              OnPropertyChanged( "BinS4Label");
          }
      }
  
      public double MasterData
      {
          get
          {
              return masterData;
          }
  
          set
          {
              masterData = value;
              OnPropertyChanged("MasterData");            }
      }
  
      public event PropertyChangedEventHandler PropertyChanged;
      private void OnPropertyChanged ( string propertyName )
      {
          if (PropertyChanged != null)
          {
              PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
          }
      }
  
  }
  </code></pre>
  
  <p>VIEWMODEL now:</p>
  
  <pre><code>public class GtlS4ViewModel
  {
      public ObservableCollection&lt;GtlS4Model&gt; gtls4Label { get; set; }
  
      DataTable dt;
      public void addTables()
      {
          dt.Columns.Add("S No.");
          dt.Columns.Add("Delivery Note");
          dt.Columns.Add("Sr No.");
          dt.Columns.Add("Customer Part No.");
          dt.Columns.Add("Bin S-4 Label");
          dt.Columns.Add("Result");
          var row1 = this.dt.NewRow();
          var row2 = this.dt.NewRow();
          var row3 = this.dt.NewRow();
          var row4 = this.dt.NewRow();
          var row5 = this.dt.NewRow();
          var row6 = this.dt.NewRow();
          row1["S No."] = 1;
          row2["Delivery Note"] = 123456;
          row3["Sr No."] = 1235143;
          row4["Customer Part No."] = 56487564;
          row5["Bin S4 Label"] = 5555656;
          row6["Result"] = 6556456454564564;
          this.dt.Rows.Add(row1);
          this.dt.Rows.Add(row2);
          this.dt.Rows.Add(row3);
          this.dt.Rows.Add(row4);
          this.dt.Rows.Add(row5);
          this.dt.Rows.Add(row6);
      }
  
      public GtlS4ViewModel()
      {
          dt = new DataTable();
          gtls4Label = new ObservableCollection&lt;GtlS4Model&gt;
          {
              new GtlS4Model {SNo = 1, DeliveryNo= 1325647, SrNo = 1515151, CustPartNo = 32156444, BinS4Label = 56456456, MasterData = 86864564564},
          };
      }            
  }
  </code></pre>
  
  <p>VIEW:</p>
  
  <pre><code>&lt;Window x:Class="Gtl_S4_Validator.Views.Window1"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
          xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
          xmlns:local="clr-namespace:Gtl_S4_Validator.Views"
          xmlns:vm="clr-namespace:Gtl_S4_Validator.ViewModel"
          mc:Ignorable="d"
          Title="Window1" Height="720" Width="525"&gt;
      &lt;Window.Resources&gt;
          &lt;vm:GtlS4ViewModel x:Key="ViewModelMain"/&gt;
      &lt;/Window.Resources&gt;
      &lt;Grid Margin="-4,0,-4,-1"&gt;
          &lt;TextBox x:Name="txtSno" HorizontalAlignment="Left" Height="24" Margin="97,23,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="82" RenderTransformOrigin="0.666,-0.434"/&gt;
          &lt;TextBox x:Name="txtDeliveryNo" HorizontalAlignment="Left" Height="21" Margin="97,61,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="82"/&gt;
          &lt;Label x:Name="label" Content="S. No." HorizontalAlignment="Left" Margin="10,21,0,0" VerticalAlignment="Top"/&gt;
          &lt;Label x:Name="label1" Content="Delivery Note" HorizontalAlignment="Left" Margin="10,59,0,0" VerticalAlignment="Top"/&gt;
          &lt;Label x:Name="label2" Content="Sr. No." HorizontalAlignment="Left" Margin="10,100,0,0" VerticalAlignment="Top"/&gt;
          &lt;Label x:Name="label3" Content="Customer Part no." HorizontalAlignment="Left" Margin="253,23,0,0" VerticalAlignment="Top"/&gt;
          &lt;TextBox x:Name="txtSrNo" HorizontalAlignment="Left" Height="23" Margin="97,100,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="82"/&gt;
          &lt;TextBox x:Name="txtCustPartNo" HorizontalAlignment="Left" Height="24" Margin="376,23,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="91"/&gt;
          &lt;Label x:Name="label4" Content="Bin S-4 Label" HorizontalAlignment="Left" Margin="253,59,0,0" VerticalAlignment="Top"/&gt;
          &lt;TextBox x:Name="txtBinS4Label" HorizontalAlignment="Left" Height="23" Margin="376,59,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="91"/&gt;
          &lt;TextBox x:Name="txtMasterData" HorizontalAlignment="Left" Height="23" Margin="376,100,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="91" RenderTransformOrigin="0.337,0.445"/&gt;
          &lt;Label x:Name="label5" Content="Master Data" HorizontalAlignment="Left" Margin="253,97,0,0" VerticalAlignment="Top"/&gt;
          &lt;Button x:Name="btnValidate" Content="Validate" HorizontalAlignment="Left" Height="27" Margin="182,141,0,0" VerticalAlignment="Top" Width="131" Click="btnValidate_Click"/&gt;
          &lt;DataGrid x:Name="GtlS4DataGrid" HorizontalAlignment="Left" Height="408" Margin="10,203,0,0" VerticalAlignment="Top" Width="505" ItemsSource="{Binding gtls4Label}" CanUserAddRows="True"&gt;
              &lt;DataGrid.Columns&gt;
                  &lt;DataGridTextColumn Header="S No"  Binding="{Binding SNo}"/&gt;
                  &lt;DataGridTextColumn Header="Delivery Note" Binding="{Binding Delivery Note}" /&gt;
                  &lt;DataGridTextColumn Header="Sr No" Binding="{Binding Sr No}" /&gt;
                  &lt;DataGridTextColumn Header="Customer Part No." Binding="{Binding CustomerPartNo }" /&gt;
                  &lt;DataGridTextColumn Header="Bin S4 Label" Binding="{Binding BinS4Label}" /&gt;
                  &lt;DataGridTextColumn Header="Result" Binding="{Binding MasterData}" /&gt;
              &lt;/DataGrid.Columns&gt;
          &lt;/DataGrid&gt;
          &lt;Button x:Name="btnExport" Content="Export" HorizontalAlignment="Left" Margin="182,616,0,0" VerticalAlignment="Top" Width="75"/&gt;
          &lt;Button x:Name="btnClear" Content="Clear" HorizontalAlignment="Left" Margin="283,616,0,0" VerticalAlignment="Top" Width="75"/&gt;
  
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <blockquote>
    <p>I don't get how am i doing it wrong but it does not add any data from the buttons also i am totally new to this environment.</p>
  </blockquote>
  
  <p>Any help will be heavily appreciated.</p>