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?
nodak said:How exactly does one go about this? In the InitializeLayout event how do you examine the value of the Object B - get the property value you want and set that value to the unbound column.
This should be fairly simple and I can't see why it would cause any performance difference at all, unless you have a really huge number of rows.
The ObjectB column will be hidden (in InitializeLayout), but it's still there. So to get the value you just reference it like you would any other cell. You will need to cast it to the appropriate type, of course, and you probably want to check for null. So... the code might look something like this:
ObjectB objectB = e.Row.GetCellValue("ObjectB") as ObjectB;
if (objectB != null)
e.Row.Cells["Prop3"].Value = objectB.Prop3;
else
e.Row.Cells["Prop3"].Value = null;
I am working with the same type of issue Mike. When you say
Mike Saltzman"] 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.
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.
How exactly does one go about this? In the InitializeLayout event how do you examine the value of the Object B - get the property value you want and set that value to the unbound column.
I was doing this in the InitalizeRow event but it has caused major performance issues even after following your recommendations in the WinGrid Performance Guide. So in seeing this post, I was going to try it in the IntializeLayout event but am having difficulty finding the right syntax.
My thanks in advance for any help provided
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.
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.