简体   繁体   中英

C# bindinglist made of bindinglists

Is there a simple way to have a bindinglist composed of several 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 always 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?

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM