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
210
How to get UltraGrid show the derived class properties of its DataDource
posted

I have Animal class and derived Cat class

: Class Animal

{

                Public String  Name{ get; set;}

}

Class Cat : Animal

{

                Public string  FurColor {get; set;}

}

Now I have ItemCollection<Animal> animals = new ItemCollection<Animal>(); with a few animal objects. Then I call UltraGrid1.DataSource = animals. The grid correctly shows the columns for the Animal properties.

If I populated the animal collection with a few cat objects. The grid only shows the properties of animal. No cat properties are shown as column of UltraGrid.

If I declare ItemCollection<Cat> cats  and set grid data source as cats. The cat properties will be shown in the UltraGrid  columns.

In WCF DataContractSerializer I can declare Cat as KnowType of Animal to get collection of anima l correctly recognized as cat. I s there a similar way for the UltraGrid  to show the actual data type  properties instead of only the base type.

Parents
  • 469350
    Suggested Answer
    Offline posted

    No, I don't believe the WinGrid can support this. There are two problems with this:

    1. The grid cannot support non-homogeneous data. That means that all of the rows in a band have to have the same columns. In this case, you appear to want to have different columns for each row and the grid cannot do that.
    2. The BindingManager in DotNet is probably going to base the data structure on the type you give it - in this case, Animal. So I don't believe it will ever return the derived-type structure.

    I could be wrong about #2, though. And if so, you might be able to acheive what you want by using the WinTree instead of the WinGrid. The WinTree has a ViewStyle called FreeForm, in which you can display non-homogeneous data. But I think you would have to generate the ColumnSets for each possible type and assign them to the nodes yourself - probably in the InitializeDataNode event.

Reply Children