I often need to traverse a multi-band grid to do various things. Many times I need to refer to the parent row but only if that row is not a GroupBy row. In that case I need to refer to .ParentRow.ParentRow. So, what I usually do is something like:
if (row.IsGroupByRow)
DoSomethingWith(row.ParentRow.ParentRow);
else
DoSomethingWith(row.ParentRow);
Although a big clunky, it works. There are some cases, however, when this approach won't work such as when I'm selecting the rows with a lambda expression such as:
var MyStuff = from UltraGridRow row in MyGrid.DisplayLayout.Bands["MyBand"].GetRowEnumerator(GridRowType.DataRow)
where <some filter>
select MyStuff
{
row.Cells["MyCell 0"].Value.ToString();
row.ParentRow.Cells["SomeCell"].Value.ToString();
}
Now, if that ParentRow is a GroupBy, then it won't work. It can be overcome using the ? : operator but again, it's clunky.
The feature I'd like to see, if it doesn't already exist, is a property on the row called ParentDataRow which would return the first parent row that is not a GroupBy Row.
I've created an extension method which accomplishes this.
public static class UltraGridRowEx { public static UltraGridRow ParentDataRow(this UltraGridRow row) { if (row.ParentRow.IsGroupByRow) return ParentDataRow(row.ParentRow); else return row.ParentRow; } }
It would be nice, however, if it were built in.
Hello Kylemwhite
Thank you for your feedback and for sharing your solution with the community. Please do not hesitate to contact us if you need any assistance.
Regards