none
Could Use some Direction in Implementing IBingingList RRS feed

  • Question

  • Well,

    I have taken the time to truly investigate the BindingList<T> class, which basically merges a Collection<T> generic class and the IBindingList Interface.  Very helpful for a start.

    My question revolves around the IBindingList Methods which involve PropertyDescriptors.  BindingList<T> does not implement this, which begs the question, how do I.  *chuckle*.  I understand what PropertyDescriptors are for, and how they are used from a reflection standpoint, as I've used them quite a few times myself.  But I have only used them, never had to implement objects that contain them, or in this case as I assume, I need to instantiate them. 

    The Collection class I have developed automatically supports sorting, which then begs the question how I would thus take advantage of this with the ApplySort and RemoveSort of the IBindingList interface.  It apparently utilizes these PropertyDescriptors yet again.  Thus I have some questions.

    1. PropertyDescriptor support for IBindingList - Does this suggest that I must create PropertyDescriptors for each property of the Collection Item?  Thus, given that PropertyDescriptor is an abstract class, this means that there wouldn't be any real way to "Defaultly" support them for descendant class, and thus for each class that descends from the Collection which implements IBindingList, i must add my own specialized property descriptors?
    2. Do the PropertyDescriptor methods only exist for the Sorting capabilities of the IBindingList Interface?  There are 5 base methods, AddIndex, RemoveIndex, ApplySort, RemoveSort, Find.  I gather these are there to describe each property in the Collection Item, (AddIndex, RemoveIndex - Would be to store the "column order" of the properties?) ApplySort & RemoveSort would be to apply sorting for the given property as described by the passed descriptor, and Find would be to find the item in the Collection whose property described by the property descriptor equals the value provided by key?

    Understanding these things would thus help me determine the best programming approach to implementing IBindingList on my existing collection class, thus adding a whole new range of support for databinding and other such pleasantries.  Currently I can use my collection class as the DataSource of a BindingSource.  However, Once set to the BindingSource.DataSource, if I change anything (add or remove entries) to the base collection, the BindingSource is not aware of this change.  In order to support that, the best course appears to be either:  Executing a ResetBindings() on the BindingSource, or implement the LIstChanged() event of IBindingSource, which will handle the update automatically.

    Thanks

    Jaeden "Sifo Dyas" al'Raec Ruiner


    "Never Trust a computer. Your brain is smarter than any micro-chip."
    PS - Don't mark answers on other people's questions. There are such things as Vacations and Holidays which may reduce timely activity, and until the person asking the question can test your answer, it is not correct just because you think it is. Marking it correct for them often stops other people from even reading the question and possibly providing the real "correct" answer.
    Sunday, April 11, 2010 3:40 AM

Answers

  • Regarding the first question, the type descriptor class has a static GetProperties(Type type) method that would return a default PropertyDescriptor implementation (obtained by reflecting the type).

    As for the second question, PropertyDescriptor methods are used to support sorting and searching of IBindingList interface.

    • Marked as answer by JaedenRuiner Sunday, April 11, 2010 2:02 PM
    Sunday, April 11, 2010 9:47 AM
  • I believe the default implementation should be enough.
    • Marked as answer by JaedenRuiner Sunday, April 11, 2010 2:02 PM
    Sunday, April 11, 2010 10:13 AM

All replies

  • Regarding the first question, the type descriptor class has a static GetProperties(Type type) method that would return a default PropertyDescriptor implementation (obtained by reflecting the type).

    As for the second question, PropertyDescriptor methods are used to support sorting and searching of IBindingList interface.

    • Marked as answer by JaedenRuiner Sunday, April 11, 2010 2:02 PM
    Sunday, April 11, 2010 9:47 AM
  • So then,

    If my collection is a collection of value types, I should be okay. 

    I guess I'm wondering if say, I have a Collection of MyClass, and MyClass has multiple properties on it.  Can I just implement the PropertyDescriptor Methods, assuming the property descriptors will exist for all the default Value Typed properties in MyClass, or do I need to create a TypeDescriptor for MyClass which will provide all the PropertyDescriptors for the MyClass object.

    Thanks

    J"SD"a'RR


    "Never Trust a computer. Your brain is smarter than any micro-chip."
    PS - Don't mark answers on other people's questions. There are such things as Vacations and Holidays which may reduce timely activity, and until the person asking the question can test your answer, it is not correct just because you think it is. Marking it correct for them often stops other people from even reading the question and possibly providing the real "correct" answer.
    Sunday, April 11, 2010 9:57 AM
  • I believe the default implementation should be enough.
    • Marked as answer by JaedenRuiner Sunday, April 11, 2010 2:02 PM
    Sunday, April 11, 2010 10:13 AM