title: WPF- How to update the changes in list item of a list
body: <p>i have updated a list item of a list.The item is successfully updated at source i.e database ,but the list is not getting updated with updated item.I have used INotifyPropertyChanged interface for the list items and the list is binded to an observable collection.</p>
  
  <pre><code>    private tbl_Model _modelItem;
      public tbl_Model ModelItem
      {
          get { return _modelItem; }
          private set
          {
              _modelItem = value;
              NotifyPropertyChanged("ModelItem");
          }
      }
  
      private ObservableCollection&lt;tbl_Model&gt; _modelCollection;
      public ObservableCollection&lt;tbl_Model&gt; ModelCollection
      {
          get { return _modelCollection; }
          private set
          {
              _modelCollection = value;
              NotifyPropertyChanged("ModelCollection");
          }
      }
  
      public void btn_update()
      {
         //Code to update at database 
         //what should i write here to update the list ?
      }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/QHxgo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QHxgo.png" alt="This is the image of the window of the list"></a></p>
  
  <p>As you can see in image,the list shows model no. as 101 even after i updated it to 102</p>
  
  <p>Thanks in advance</p>
  
  <p>The auto generated model via Linq to Sql</p>
  
  <pre><code> public partial class tbl_Model : INotifyPropertyChanging, INotifyPropertyChanged
  {
  
      private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);
  
      private int _ID;
  
      private string _Model_No;
  
      private string _Name;
  
      private string _Manufacturer;
  
      private int _IsDelete;
  
  #region Extensibility Method Definitions
  partial void OnLoaded();
  partial void OnValidate(System.Data.Linq.ChangeAction action);
  partial void OnCreated();
  partial void OnIDChanging(int value);
  partial void OnIDChanged();
  partial void OnModel_NoChanging(string value);
  partial void OnModel_NoChanged();
  partial void OnNameChanging(string value);
  partial void OnNameChanged();
  partial void OnManufacturerChanging(string value);
  partial void OnManufacturerChanged();
  partial void OnIsDeleteChanging(int value);
  partial void OnIsDeleteChanged();
  #endregion
  
      public tbl_Model()
      {
          OnCreated();
      }
  
      [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_ID", AutoSync=AutoSync.OnInsert, DbType="Int NOT NULL IDENTITY", IsPrimaryKey=true, IsDbGenerated=true)]
      public int ID
      {
          get
          {
              return this._ID;
          }
          set
          {
              if ((this._ID != value))
              {
                  this.OnIDChanging(value);
                  this.SendPropertyChanging();
                  this._ID = value;
                  this.SendPropertyChanged("ID");
                  this.OnIDChanged();
              }
          }
      }
  
      [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Model_No", DbType="VarChar(50) NOT NULL", CanBeNull=false)]
      public string Model_No
      {
          get
          {
              return this._Model_No;
          }
          set
          {
              if ((this._Model_No != value))
              {
                  this.OnModel_NoChanging(value);
                  this.SendPropertyChanging();
                  this._Model_No = value;
                  this.SendPropertyChanged("Model_No");
                  this.OnModel_NoChanged();
              }
          }
      }
  
      [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Name", DbType="VarChar(50) NOT NULL", CanBeNull=false)]
      public string Name
      {
          get
          {
              return this._Name;
          }
          set
          {
              if ((this._Name != value))
              {
                  this.OnNameChanging(value);
                  this.SendPropertyChanging();
                  this._Name = value;
                  this.SendPropertyChanged("Name");
                  this.OnNameChanged();
              }
          }
      }
  
      [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Manufacturer", DbType="VarChar(50) NOT NULL", CanBeNull=false)]
      public string Manufacturer
      {
          get
          {
              return this._Manufacturer;
          }
          set
          {
              if ((this._Manufacturer != value))
              {
                  this.OnManufacturerChanging(value);
                  this.SendPropertyChanging();
                  this._Manufacturer = value;
                  this.SendPropertyChanged("Manufacturer");
                  this.OnManufacturerChanged();
              }
          }
      }
  
      [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_IsDelete", DbType="Int NOT NULL")]
      public int IsDelete
      {
          get
          {
              return this._IsDelete;
          }
          set
          {
              if ((this._IsDelete != value))
              {
                  this.OnIsDeleteChanging(value);
                  this.SendPropertyChanging();
                  this._IsDelete = value;
                  this.SendPropertyChanged("IsDelete");
                  this.OnIsDeleteChanged();
              }
          }
      }
  
      public event PropertyChangingEventHandler PropertyChanging;
  
      public event PropertyChangedEventHandler PropertyChanged;
  
      protected virtual void SendPropertyChanging()
      {
          if ((this.PropertyChanging != null))
          {
              this.PropertyChanging(this, emptyChangingEventArgs);
          }
      }
  
      protected virtual void SendPropertyChanged(String propertyName)
      {
          if ((this.PropertyChanged != null))
          {
              this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
          }
      }
  }
  </code></pre>
  
  <p>The ListView XAML Code</p>
  
  <pre><code>&lt;ListView ItemsSource="{Binding ModelCollection,Mode=TwoWay}" SelectedItem="{Binding SelectedModelItem}" Style="{StaticResource viewinglist}"&gt;                      
                      &lt;ListView.View&gt;
                          &lt;GridView&gt;
                              &lt;GridViewColumn DisplayMemberBinding="{Binding Model_No, Mode=TwoWay}" Header="Model No." Width="100"/&gt;
                              &lt;GridViewColumn DisplayMemberBinding="{Binding Name, Mode=TwoWay}" Header="Model Name"  Width="200"/&gt;
                              &lt;GridViewColumn DisplayMemberBinding="{Binding Manufacturer, Mode=TwoWay}" Header="Manufacturer"  Width="200"/&gt;
                          &lt;/GridView&gt;
                      &lt;/ListView.View&gt;
                  &lt;/ListView&gt;
  </code></pre>
  
  <p>Solution for anyone who sees the post:</p>
  
  <p>This is where i was doing wrong-:
       public tbl_Model SelectedModelItem {get; set;}</p>
  
  <pre><code> //on clicking edit this is what i used to do
    ModelItem.ID = SelectedModelItem.ID;
    ModelItem.Model_No = SelectedModelItem.Model_No;
    ModelItem.Name = SelectedModelItem.Name;
    ModelItem.Manufacturer = SelectedModelItem.Manufacturer;
  </code></pre>
  
  <p>The right way :</p>
  
  <pre><code>  private tbl_Model _selectedModelItem;
      public tbl_Model SelectedModelItem 
      {
          get { return _selectedModelItem; }
          set
          {
              _selectedModelItem = value;
              NotifyPropertyChanged("SelectedModelItem");
          } 
      }
  
  
     on clicking edit
  
     ModelItem = SelectedModelItem;
  </code></pre>