I have a whdg and need to access the child rows from the parent row. More specifically, one of the columns on the parent row uses information from the child band to set its value. I have tried to get the information through the initialize row event as follows:
protected void whdg1_InitializeRow(object sender, RowEventArgs e)
{
//There is no method on e to get the child rows
}
I am looking for something that is similar to the Rows method in the UltraGrid:
UltraGridRow row;
Hi bpg730,
To access the child rows of a row, you have to go through its RowIslands collection to get to its child grids first. So in this example.
ContainerGridRecord row = (ContainerGridRecord)e.Row; ContainerGridRecordCollection childRows = row.RowIslands[0].Rows;
Although depending upon load on demand and whether the children have been bound yet, these might not be available.
regards,David Young
In the small test case that I built, I create and bind the data on the page load event. I tried what you said both with the default load on demand behavior and with the initialDataBindDepth set to -1 to load all of the children (there is only one child band) but in both cases the row variable has 0 elements. Is there a way to change my grid to be able to have your example work or is there another way to access the child rows?
I have set the initialDataBindDepth = 1 in the grid. I have changed the initialize row event as follows:
ContainerGridRecord row = (ContainerGridRecord)e.Row;
if (row.RowIslands.Count > 0)
//Do stuff
But the row never gets into the if loop. Do you have any other suggestions?
Hey,
This is because when the rows for the first grid view are created, the child grids have not been initialized yet. So you either need to handle DataBound and change your values there. Or you could handle RowIslandCreated and go up to the parent row and modify the value.
-Dave