views:

161

answers:

2

Hi,

Is there a simple way to have a bindinglist composed of serveral bindinglists ? ie that is the "view" of the lists.

That is to say : I have 3 lists (list1,list2,list3). I want a list that is alway the union of the 3 listx (we can suppose that no object is contained in 2 different lists).

Certainly, I can succeed in using the ListChange property but maybe there is a smarter way to do this ?

Thx

+1  A: 

To do this you would need to create your own type, implement IList, IBindingList (and ideally IBindingListView), and optionally ICancelAddNew and IRaiseItemChangedEvents. You'd also need either a public non-object indexer (public T this[int index] {get;}) or ITypedList.

From having done things similar to this, I strongly advise you; don't, unless this is really important. It would be more pragmatic to copy the references into a new BindingList<>.

Also; with new items; which list would it go into?

Marc Gravell
I only want the view of the inner list, new items will be directly added to one of the inner list
Toto
+1  A: 

Have you looked into the CompositeCollection class?

Depending on what you're trying to do, it might help: its purpose is to combine multiple collections into a single collection (typically for display/binding purposes). So, you could create a CompositeCollection and add your three BindingList instances to it. The CompositeCollection will automatically update to include the members of the "child" lists.

Dan Puzey
That one is new to me; cheers!
Marc Gravell
You can build the `CompositeCollection` in code or in Xaml, too. It can be quite flexible!
Dan Puzey