Click here to Skip to main content
15,888,050 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good Morning,

so i have spent the last 4 days getting my knowledge up on mvvm pattern,

however i have been unable to get the desired result back

so figured out why i could not load data into my datagrid,

this has now been resolved,

however i want to select a row and edit a value in one of the data grid values,

and receive an update from with all values on that row,

i have managed to create a selected Pump and wire that too selected row command,

this returns the selected row,

result

however, this is before i edit it and after i edit it does not update unless i go off the row and back onto it witch is not what i want,

so i have added a on property changed event in my pumptype class,

private int _PumpNo;

  public int PumpNo
  {
      get { return _PumpNo; }
      set
      {
          _PumpNo = value;
          OnPropertyChanged("PumpNo");
      }
  }


  private int _State;

  public int State
  {
      get { return _State; }
      set
      {
          _State = value;
         this.OnPropertyChanged("State");
      }
  }


  private int _Stan;

  public int Stan
  {
      get { return _Stan; }
      set
      {
          _Stan = value;
          this.OnPropertyChanged("Stan");
      }
  }


  private int _GradeId;

  public int GradeId
  {
      get { return _GradeId; }
      set
      {
          _GradeId = value;
          OnPropertyChanged("GradeId");
      }
  }

  private string _GradeName;

  public string GradeName
  {
      get { return _GradeName; }
      set
      {
          _GradeName = value;
          OnPropertyChanged("GradeName");
      }
  }

  private int _Ppu;

  public int Ppu
  {
      get { return _Ppu; }
      set
      {
          _Ppu = value;
          OnPropertyChanged("Ppu");
      }
  }

  private int _Volume;

  public int Volume
  {
      get { return _Volume; }
      set
      {
          _Volume = value;
          OnPropertyChanged("Volume");
      }
  }

  private int _Cash;

  public int Cash
  {
      get { return _Cash; }
      set
      {
          _Cash = value;
          OnPropertyChanged("Cash");
      }
  }

  private bool _MobileTransaction;

  public bool MobileTransaction
  {
      get { return _MobileTransaction; }
      set
      {
          _MobileTransaction = value;
          OnPropertyChanged("MobileTransaction");
      }
  }

  private bool _MobileEnabled;

  public bool MobileEnabled
  {
      get { return _MobileEnabled; }
      set
      {
          _MobileEnabled = value;
          OnPropertyChanged("MobileEnabled");
      }
  }



and then tryied to create a call in the constructor
for when the property is changed. in the class that does work the onproperty changed is trigged in the pumptype class

however the implication in the mainviewmodel class does not get hit when this is changed

public MainWindowViewModel()
{
    elfendb.InitialzePumps();
    Pumps = new ObservableCollection<PumpType>();
    elfenliedpump.PropertyChanged += Elfenliedpump_PropertyChanged;
    foreach (var item in elfendb.Pumps)
    {

        Pumps.Add(item);

    }

}

private void Elfenliedpump_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
    int statenumber = 0;
    if (e.PropertyName == "State")
        RaisePropertyChanged("statenumber");
}


however when the property changes in pumptype class this does not trigger on on the made methord does not even enter it

and have break pointed the state on pumptype and when i change this it does get flagged in pumptype but does not send this down to the mainwindowviewmodel

anyone have any idea why it would do this.

What I have tried:

i have also tried to do the cell edit from the code behind but decided against that as its not true mvvm and spend days on trying to do this i even installed

mvvm toolkit and tried to send the message but as i subscribe multiple times as all pumps values are in a observable collection gets called multiple times and the weakrevrencemessanger throws up an exception saying already subscribed to had to forget this one

any help would be much appreciated kind regards,
elfenliedtopfan5
Posted
Updated 26-Mar-23 22:52pm

1 solution

Here, watch this video:"WPF Controls with MVVM: DataGrid - YouTube[^]. There is a source code download link as well.

Here is a search with more videos for you: mvvm datagrid | YouTube[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900