Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
615
Trouble binding to custom IList implementation
posted

I've had some trouble lately binding the UltraGrid to a custom collection. I've got a class hierarchy/organization as follows:

  • An abstract base class from which a number of business objects are derived.
  • An abstract generic custom collection class that is constrained to the abstract base class and implements the IList interface as well as having a single custom property.
  • A concrete business class that derives from the abstract base class
  • a concrete collection class that derives from the abstract collection class and is typed to the concrete business class. This class adds its own custom property.

In my solution I've instantiated one of these custom collections (and added items to it) and set it to the grid's DataSource but what I see are the columns based on the two custom properties available from the collection class hierarchy (i.e. one from the base class and one from the derived class) rather than the properties of the business object (i.e. the type of the collection).

Interestingly when I try to use a binding source I do see the structure as initially expected but I get a type error when attempting to add items through the binding source.

Before delving too deeply into figuring out the binding source issue I'd like to know if there is some factor I'm missing when attempting to bind directly to the grid. Hope you guys can shed some light on this one.

 

thanks

Parents
No Data
Reply
  • 469350
    Offline posted

    Hi,

    I'm having some trouble understanding some of your set up. What exactly do you mean by "custom property?" What's custom about it?

    The WinGrid will bind to the structure that it gets from the BindingManager. If you bind the grid to a generic list of a base class, then the grid and the BindingManager will only reveal properties on the base class - it does not matter what the actual objects populating the list are.

    The WinGrid does not support displaying heterogenous data. All of the items in the list must have the same column structure. You cannot have a row with different columns that any other row in the same band.

    zenophite said:
    Interestingly when I try to use a binding source I do see the structure as initially expected but I get a type error when attempting to add items through the binding source.

    I've never heard of the BindingSource making any difference in a case like this. But maybe this is something new. I know there are cases where the BindingManager is unable to retrieve the data structure from the list and what it does in those cases is look at the first item in the list, or if there are no items, it will attempt to add an item, get the structure, and then cancel the new item. So maybe that's what is happening here.

Children