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.
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; } }
Exactly what I needed, thanks for the solution and explanation!
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
Sorry I don't have time to make a sample project. For now I am doing this to get going, a not too bad solution :)
if (e.Layout.Bands[0].Layout.Grid.Rows.Count ==1) { //Due to an Infragistics bug, this line stops working inside an if statement, it works if I remove the if, very strange //e.Layout.Bands[0].Override.GroupByRowInitialExpansionState = GroupByRowInitialExpansionState.Expanded; _grid.Rows.ExpandAll(true); //because above line not working, using this instead to expand all bands which is not as good }
-Steve
Hi Steve,
Well, then I am out of ideas. :)
If you can provide a small sample project, we can check it out, but we have to be able to reproduce the issue in order to see what's going on. BTW... you should probably start a new thread, so we can create a case for you.
Hi Mike,
We are using 2013 Vol2. And adding e.Layout.Grid.Update() like below doesn't work (just FYI, tried adding it after the expanded line didn't work either):
{
e.Layout.Grid.Update();
}
What version of the grid are you using? This sounds like a bug we recently fixed internally - the fix is not yet publicly available. Try calling e.Layout.Grid.Update() right before you set the GroupByRowInitialExpansionState property and see if that helps.
If not, then see if you can reproduce the problem in a small sample project and post it here and I will be happy to take a look.