1

I have implemented group observable collection like below.

Grouped Property

private ObservableCollection<Grouping<String, Request>> _groupedList = null;
public ObservableCollection<Grouping<String, Request>> GroupedList {
    get {
        return _groupedList;
    }
    set {
        _groupedList = value;
        RaisePropertyChanged(() => GroupedList);
    }

}

Creating List

var list = new List<Request>();

var grouped = from Model in list
                         group Model by Model.Done into Group
                         select new Grouping<string, Request>(Group.Key, Group);

GroupedList = new ObservableCollection<Grouping<string, TModel>>(grouped);

Now i need to update one item in the list without reloading full list for performance.

i did tried like this , mylist.FirstOrDefault(i => i.Id== mymodel.Id); Not worked for me.

I need to pick that particular item and edit and update into the list again using linq or something but i stuck here for group observable collection no efficient details to do this., anybody having idea about this help please.

And finally i get updated single item, but i need to do that without

GroupedList = new ObservableCollection<Grouping<string, TModel>>(grouped);

Because everytime it create new list and bind into my view.Thats again big performance though. Thanks in advance.

Riyas
  • 475
  • 1
  • 8
  • 27

1 Answers1

1

What I understand from your question is that you want to push an updated group without overwriting the entire ObservableCollection.

To do that:

var targetGroup = GroupedList.FirstOrDefault(i => i.Id == mymodel.Id);
var targetIndex = GroupedList.IndexOf(targetGroup);
var modifiedGroup = ... //Do whatever you want to do
GroupedList[targetIndex] = modifiedGroup;

This will trigger a 'replace' operation of the target grouping.

David Oliver
  • 2,251
  • 12
  • 12
  • one doubt where is that `targerList` come from suddenly, And one more i can't do `var targetGroup = GroupedList.FirstOrDefault(i => i.Id == mymodel.Id);` i tried this but somehow its not suitable , i cant get id from it. – Riyas Sep 07 '17 at 05:45
  • Finally this works with little modification, Thanks for the help @David Oliver – Riyas Sep 07 '17 at 06:49