DavidA
DavidA

Reputation: 475

Merging Two ObservableCollections

I have two Observable Collections that I need to merge into one collection.

This arises because I have two methods, getTasks(staffID) which returns an ObservableCollection and getTasks(teamID) which selects the staff and pulls back the staff tasks.

For the teams I will have multiple small observableCollections, I just want to merge them.

Upvotes: 7

Views: 14971

Answers (3)

Samo
Samo

Reputation: 2181

This is what worked for me:

Concat or Union, but the result is a IEnumerable, so it needs to be converted back into an ObservableCollection:

var result = new ObservableCollection<T>(list1.Concat(list2));

Upvotes: 9

Matt DeKrey
Matt DeKrey

Reputation: 11932

I found a reference to CompositeCollection on another SO article: Merged ObservableCollection

Since you're looking to do a Concat/Union, this seems to do exactly that. Too bad it's not strongly typed.

Upvotes: 5

DavidA
DavidA

Reputation: 475

I went with volkerK's suggestion and then moved to:

http://msdn.microsoft.com/en-us/library/system.linq.enumerable.union.aspx Ta

Upvotes: 0

Related Questions