0

So, I have a table with 3 columns (location, onhand, committed). When a user clicks on a particular row, a pop window is displayed which allows a user to change the value of "committed". Hence, when the pop is closed, I want to see the updated value in the table. However, that is not the case although the value has already been updated in the db. Can someone tell me where am I making a mistake in the code?

I followed this answer but it didn't help me.

Her'es my View Code:

<DataGrid.Columns>

   <DataGridTextColumn Width="Auto" Header="OnHand" Binding="{Binding Path= OnHand,Mode = TwoWay,UpdateSourceTrigger=PropertyChanged }" />

</DataGrid.Columns>

Here's how I populate the grid:

foreach (var item in inventoryList)
{

     items.Add(new InventoryDto { location = item.location.Name, OnHand = item.OnHand.ToString(), committed = item.committed.ToString() });

}
InventoryDataGrid.ItemsSource = items;

Here's the class:

class InventoryDto : INotifyPropertyChanged
    {

        public string location { get; set; }
        public string onHand { get; set; }
        public string committed { get; set; }



        public InventoryDto()
        {

        }

        public InventoryDto(string location, string OnHand, string committed, string productId)
        {
            this.location = location;
            this.onHand = OnHand;
            this.committed = committed;

        }


        public string OnHand
        {
            get
            {
                return onHand;
            }
            set
            {
                onHand = value;
                OnPropertyChanged("OnHand");
            }
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;
        private void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        #endregion
    }
mcfred
  • 1,183
  • 2
  • 29
  • 68
  • Do you use the same instance of InventoryDto for datagrid and popup? – El Barrent Jul 23 '18 at 10:30
  • InventoryDto is only used to populate datagrid. PopWindow allows the user to change the value, and when the user presses ok button, the productId associated with that row is captured and the SQL is executed. – mcfred Jul 23 '18 at 10:37
  • Then how InventoryDto may know that there is some update on database side? You should update InventoryDto when user clicks button. – El Barrent Jul 23 '18 at 10:56
  • Why do I have to update inventoryDto while I have already used inotifypropertychange on "OnHand". So, if the value in db changes, shouldn't it trigger the change in the UI as well? – mcfred Jul 23 '18 at 10:57
  • How is InventoryDto connected to database in code? There is no magic in INorifyPropertyChange – if no one updates property explicitly and raise PropertyChanged event, then there is no way for UI to know about updates. – El Barrent Jul 23 '18 at 12:08

0 Answers0