I have a UltraDataGrid that I've bound to an UltraDataSource. My data source has two levels.
I am having trouble accessing the child bands through the grid. I know that myDataGrid.Rows exposes a RowsCollection for band 0 (the top-level band). What I would like to do is get a RowsCollection for any of the child bands that I have defined in my UltraDataSource.
I have tried code like this, but it still only gives me the top-level rows:
foreach (UltraGridBand band in this.detectionUltraGrid.DisplayLayout.Bands){ foreach (UltraGridRow row in band.Layout.Rows) { // This RowsCollection is the top level foreach (UltraGridCell cell in row.Cells) { if (cell.Value == DBNull.Value) { cell.Hidden = true; } } }
}
How do I get to the child rows?
Thanks,Ben
With some help, I think I figured out one way to access the child bands:
foreach (UltraGridRow row in this.myUltraGrid.Rows){ foreach (UltraGridChildBand childBand in row.ChildBands) { foreach (UltraGridRow childRow in childBand.Rows) { foreach (UltraGridCell cell in childRow.Cells) { if (cell.Value == DBNull.Value) { cell.Hidden = true; } } } } }
Is there a better way? With less nesting?:)
If all you're trying to do is hide a cell if it's value is null, your best option is to simply use the InitializeRow event and check to see if the cell's Value is null there, and possibly that its Band's Key is what you're looking for.
-Matt
I am trying to change the value of the childrow column on InitializeRow event.
with e.Row.Column i can just access the parent row columns but not the child.
can any one help me how to do it.
InitializeRow will fire for each row, both parent and child rows. So if you are using InitializeRow, it does not make sense to change the value of any row except the row for which the event is firing.
However, if you need to access a child row of a particular parent row, you do it like so:
row.ChildBands[child band index].Rows[child row index]
If you want to loop through all of the rows in the grid without writing nested loops, you could do this:
foreach (UltraGridRow row in this.ultraGrid1.Rows.GetFilteredInNonGroupByRows())
Thanks Mike..
I got my problem solved. Also same can be done by checking the band.
Everytime when InitializeRow fires it has a unique band associated with it. I checked e.row.band. If it was as same as the child band i did my processing.