Re: Questions about binding to heterogeneous collections and to base classes?

WinForms

ComponentOne's WinForms controls

Questions about binding to heterogeneous collections and to base classes?

  • rated by 0 users
  • This post has 1 Reply |
  • 0 Followers
  • Hi,

    1. Is it possible to bind to a IList<object> where the items in the list are not all of the same type I.e. A heterogeneous list as opposed to a homogenous list?

    2. If I bind the InputPanel to IList<MyBaseClass> it only displays the properties declared in MyBaseClass, even if all of the objects in the List are of type MySubClass. 

        a. Is this expected behaviour? 

        b. If so, is there a way I can get the InputPanel to create controls for the derived class properties, without having to convert the IList<MyBaseClass> to IList<MySubClass>?

     Kind regards,

    Paul

  • Hi Paul,

    > 1. Is it possible to bind to a IList<object>

    It is preferable to use BindingList<T> instead of List<T>, or rather
    IBindingList instead of IList. The binding list supports notifications
    and other features required for normal data binding.

    > where the items in the list are not all of the same type
    > I.e. A heterogeneous list as opposed to a homogenous list?

    I think, no. I may be missed something though.

    > 2. If I bind the InputPanel to IList<MyBaseClass> it only displays
    > the properties declared in MyBaseClass, even if all of the objects
    > in the List are of type MySubClass. 
    >
    >    a. Is this expected behaviour? 

    Yes. It doesn't take a look at the objects. It looks only at the
    declared type of the list item.

    >
    >    b. If so, is there a way I can get the InputPanel to create controls
    > for the derived class properties, without having to convert the
    > IList<MyBaseClass> to IList<MySubClass>?

    You may create the IList<MySubClass>, bind it to the input panel to
    create controls, then call the C1InputPanel.SetDataBinding() method
    passing IList<MyBaseClass> in the first parameter and 'false' in the
    last (populate). This doesn't repopulate the panel with controls.

    Regards,

    -Andrey
Page 1 of 1 (2 items)