开发者

C# bindinglist made of bindinglists

开发者 https://www.devze.com 2022-12-29 03:36 出处:网络
Is there a simple way to have a bindinglist composed of several bindinglists? i.e. that is the \"view\" of the lists.

Is there a simple way to have a bindinglist composed of several bindinglists? i.e. 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,开发者_Go百科 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号