Hi;
we bound a xamDatagrid to a ViewModel like so:
using System; public class ClassA: ObservableModel { public string Id { get; set; } public ObservableCollection<ClassB> ListB { get; set; } } public class ClassB : ObservableModel { public string Id { get; set; } public ObservableCollection<ClassC> ListC { get; set; } } public class ClassC : ObservableModel { public string Id { get; set; } } public class ViewModel { public ObservableCollection<ClassA> ListA { get; set; } public ViewModel() { this.ListA = new ObservableCollection<ClassA>(); } } <igDP:XamDataGrid Name = "xamDataGrid1" DataSource="{Binding ListA}" >
To edit instances from type classC we have a modal Dialog. The Dialog starts by doubleclick in the corresponding Row of the grid. If the Dialog Returns with true, the datas are stored in DB. To refresh the Grid we use following Code
void refeshItem(string Id) { // get the new datas from db var datas = await getDatasByIdFromDbASync(Id).ConfigureAwait(true); ClassC existC = null; ClassB existB = null; int indexOfC = -1; // look for old item foreach (var a in this.ListA) { foreach (var b in a.ListB) { existC = b.ListC.FirstOrDefault(p => p.Id == datas.Id); if (null != existC) { existB = b; indexOfC = b.ListC.IndexOf(existC); break; } } if (null != existC) break; } if (indexOfC == -1) return; if (null == existB) return; if (null == existC) return; // Invoke the Collection changed event with Remove: OK existB.ListC[indexOfC] = datas; datas.OnPropertyChanged(); }
But the Datarecords are not refreshed. Any suggestions?
Regards Torsten
Hallo Mike,Thank you for you quick answer. I found my bug. In the 'getter' of the ObservableCollection I always returned a new Collection like so:
public class ClassBViewModel { public ClassBViewModel() { ; } public ClassBPoco Poco { get; set; } public string Id { get; set; } public ObservableCollection<ClassCViewModel> ListC { get { if (null == Poco || null == Poco.ListC) return new ObservableCollection<ClassCViewModel>(); var result = new ObservableCollection<ClassCViewModel>(); foreach (var c in Poco.ListC) result.Add(new ClassCViewModel(c)); return result; } } }
So, my 'refreshItem' method never saw the Collection from the GUI.
RegardsTorsten