How can I databind to properties not associated with a list item in classes deriving List

前端 未结 3 818
無奈伤痛
無奈伤痛 2021-01-13 16:31

Previously, I had a class that wrapped an internal System.Collections.Generic.List (where Item is a class I created). The wrapper class provided se

3条回答
  •  孤城傲影
    2021-01-13 16:45

    The problem here is that you want to use your one class for two completely different purposes (in terms of bindings).

    Example: The "AverageValue" property doesn't make sense to be on each item, because it's a global property that spans all items.

    Either way, I'm guessing that your _itemsBindingSource is for a ComboBox or something, and that your _summaryBindingSource is for a PropertyGrid (or something like that).

    What you could do, that might work in your situation (I can't be certain because I don't know what you are actually doing) is this:

    1) Make your "OldClass" implement IEnumerable... and in that, simply return the enumeration from the list. That will give you the ability to bind to "oldClass" instead of "oldClass.Items".

    2) Make the "public List Items" a field, instead of a property... or add the "Browsable(false)" attribute so it won't get bound to the PropertyGrid (this is a guess as it's unclear what you're using these bindings for).

提交回复
热议问题