2017-04-20 7 views
0

通常のcolletionでは、私はCollectionName.Remove(item);を使用します。誰かが私にItemsGroupedコレクションからアイテムを削除する方法を教えてもらえますか?

しかし、<Grouping <string, Device>とこのcolletionでは、私はこれを行う方法を理解していません。リストビューを更新するにはアイテムを削除する必要があります。

すべての援助を歓迎します。ありがとうございます!

のViewModel:

コンストラクタ:

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); 
      } 
     } 
+0

おそらくこれはhttp://stackoverflow.com/questions/9743420/remove-an-item-from-an-observablecollection-in-a-collectionchanged-event-handler答えがあなたを助けることができます。 –

+0

こんにちは私の友人、あなたの助けを大変ありがとう! – user2530802

答えて

1

私はグループ化されたコレクション内の項目を削除する代わりに、グループ化の源ではないでしょう。

すでにオリジナルコレクションDevicesのコピーがありますので、そこにあるアイテムを削除してグループ分けをやり直してください。

+0

こんにちは私の友人、私はあなたの提案に従って、問題を解決し、あなたの助けを大変ありがとう! – user2530802

関連する問題