Hi!
We have a xamWebGrid in our application with grouping enabled. For this grid we have a button for expanding all rows. I copied the code for expanding all rows from the samples browser:
public void ExpandRows(RowCollection rows) { foreach (Row row in rows) { row.IsExpanded = true;
if (row.HasChildren) { ExpandRows(row.ChildBands[0].Rows); } } }
When I click Expand I get an exception in the ExpandRows method on this line: ExpandRows(row.ChildBands[0].Rows);
The exception:
- row.ChildBands 'row.ChildBands' threw an exception of type 'System.InvalidCastException' Infragistics.Silverlight.Controls.Primitives.ChildBandCollection {System.InvalidCastException}
- base {System.InvalidCastException: Unable to cast object of type 'Infragistics.Silverlight.Controls.RowCollection' to type 'Infragistics.Silverlight.Controls.Primitives.ChildBandCollection'.
at Infragistics.Silverlight.Controls.Row.get_ChildBands()
at Infragistics.Silverlight.Controls.Primitives.GroupByRow.get_ChildBands()} System.SystemException {System.InvalidCastException}
Do you have any idea how this can be solved?
Thanks,
Arjen
Guys
I am good thanks. I was not using the right namespace and was getting error.
the solution provided above by Steve helped.
Hai
I have the same requirement, but should be expanded without any clicks right after the users sees the screen
what even should i use and , how to get rowcollectoin
i see this event only
xamgrid1_GroupByCollectionChanged
Hi Steve,
That did it. Thanks for the quick reply!
Hi Arjen,
The exeption you're getting, is b/c GroupByRows have a Rows, and wouldn't have ChildBands. Here is a modified version of that function:
private void ExpandRows(RowCollection rows)
{
if (rows.Count > 0)
if (rows[0].RowType == RowType.GroupByRow)
// Expand GroupByRows
foreach (GroupByRow row in rows)
row.IsExpanded = true;
if (row.HasChildren)
this.ExpandRows(row.Rows);
}
else
// Expand DataRows
foreach (Row row in rows)
this.ExpandRows(row.ChildBands[0].Rows);
Hope this helps,
-SteveZ