I am programmatically adding 2 group by rows to my grid (I would prefer to do this in the Designer but understand this is not possible?) using the following:
grid.DisplayLayout.Bands[0].SortedColumns.Add("ColOne", false, true);grid.DisplayLayout.Bands[0].SortedColumns.Add("ColTwo", false, true);
I would like to have the ColOne group expanded by default, and the ColTwo group collapsed by default.
Nothing I do to programmatically expand/collapse rows has any effect, e.g. grid.ExpandAll(), row.Expanded = true, row.ExpandAll() etc. When I inspect the Rows collection e.g. within InitializeLayout there are no UltraGroupByRows in the collection, only data rows - is this expected? I do see the group by rows on-screen at run-time.
The only thing which has any effect on expanding rows is setting
ultraGridBand1.Override.GroupByRowInitialExpansionState = Infragistics.Win.UltraWinGrid.GroupByRowInitialExpansionState.Expanded; However, that expands both groups whereas I would only like to expand the parent group.
Am I approaching this in the right way, and if so why can't I expand any rows programmatically? Any help appreciated, thanks.
There is such a strange behavior with GroupByRowInitialExpansionState.
I have a multiple band grid build by using relations, something like ds.Relations.Add(...
Each band I have a different set of groupby columns.
Now I wanted to expand the first band if there is only one row of data in the first band as code below in AfterInitializeLayout event:
if (e.Layout.Bands[0].Layout.Grid.Rows.Count == 1)
e.Layout.Bands[0].Override.GroupByRowInitialExpansionState = GroupByRowInitialExpansionState.Expanded;
When I debug through this code, I saw it executed the below line:
But the Bands[0] is NOT expanded!
However, if I remove the if line (if (e.Layout.Bands[0].Layout.Grid.Rows.Count == 1) ) then the Bands[0] will be expanded (but obviously, it will expand always, even when there are multiple rows in the Bands[0], which is not what I wanted) !
Please let me know what’s going on?
Thanks
Steve
Exactly what I needed, thanks for the solution and explanation!
Hi,
P Robinson said:I would prefer to do this in the Designer but understand this is not possible?
It is possible if your data source and data structure exists at design-time.But there's no reason why you can't do it at run-time - although personally, I recommend using the InitializeLayout event of the grid.
P Robinson said:Nothing I do to programmatically expand/collapse rows has any effect, e.g. grid.ExpandAll(), row.Expanded = true, row.ExpandAll() etc. When I inspect the Rows collection e.g. within InitializeLayout there are no UltraGroupByRows in the collection, only data rows - is this expected? I do see the group by rows on-screen at run-time.
The grouping is handled asynchronously. So what's happening here makes sense.You could probably force the rows to be created by forcing the grid to paint by calling grid.Update(). But this is not a great way to do it.
I would do it like this:
void ultraGrid1_InitializeGroupByRow(object sender, InitializeGroupByRowEventArgs e) { if (false == e.ReInitialize && e.Row.Column.Key == "ColOne") { e.Row.Expanded = true; } }