0

In a normal colletion I would use CollectionName.Remove(item);

But in this colletion with <Grouping <string, Device> I do not understand how to do this. I need to remove the item to update my ListView.

All help is welcome, thank you!

ViewModel:

Constructor:

var sorted = from item in Devices
                         orderby item.Grupo
                         group item by item.Grupo.ToString() into itemGroup
                         select new Grouping<string, Device>(itemGroup.Key, itemGroup);

            ItemsGrouped = new ObservableCollection<Grouping<string, Device>>(sorted);
public ObservableCollection<Device> Devices
{
    get { return _devices; }
    set
    {
        _devices = value;
        OnPropertyChanged();
    }
}

public ObservableCollection<Grouping<string, Device>> ItemsGrouped { get; set; }




 public class Device:ViewModelBase
        {
            public int ID { get; set; }

            public string Title { get; set; }
            public string Description { get; set; }
            public string Image { get; set; }
            public string Grupo { get; set; }
        }



public class Grouping<K, T> : ObservableCollection<T>
        {
            public K Key { get; private set; }

            public Grouping(K key, IEnumerable<T> items)
            {
                Key = key;
                foreach (var item in items)
                    this.Items.Add(item);
            }
        }
user2530802
  • 119
  • 2
  • 10

1 Answers1

1

I wouldn't delete the item in the grouped collection but instead in the source of the grouping.

You already have a copy of the original collection Devices, remove the item there and re-do the grouping.

pinedax
  • 9,246
  • 2
  • 23
  • 30