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
145
Nested Objects Binding to the UltraWinGrid
posted

I have a custom Object A, which has a reference to the Object B and two string type properties lets say Prop1,Prop2. Object B also has a string property called prop3. Now when I bind the A to UltraWingrid.

So i have a nested object structure. In my grid, Now I want three columns , third column with the value of prop3 of Object B.

I am trying to change the value of rows third cell value by getting the prop3 values from the ObjectB. But it does not allow me to do so.

Error is of Type casting to ObjectB to string value. How do I handle this?

 

 

Parents
No Data
Reply
  • 469350
    Suggested Answer
    Offline posted

    Hi,

    The grid can't walk down into Object B and promote it's properties to columns. What will happen here is that your grid will show three columns: Prop1, Prop2, and Object B.

    Since Object B is a class, the grid can't know how to edit it. It will display the cells of the column by calling the ToString method on Object B, but it can't know what to do if the user types into the cell. The grid has no way of taking a string that the user types in and converting it into an Object B instance.

    There are a couple of ways you could deal with this.

    The easiest way I can think of would be to use an unbound column. What you do is handle the grid's InitializeLayout event and hide the Object B column using the column's Hidden property. Then you add an unbound column to the grid for Prop3.

    In the InitializeLayout event of the grid, you examine the value of the Object B column and get the Prop3 value and then set the value of the unbound column to that value.

    Then in the AfterCellUpdate event, you trap for changes in the Prop3 (unbound) column and copy those changes into the Object B instance in the Object B cell in the same row.

Children