Hello there
I'm trying to expand all Rows programmatically which _usually_ works with the following code:
var filterViewModels = PivotGrid.DataSource.Rows.Where(fvm => fvm is IFilterViewModel).ToList();
for (int i = 0; i < filterViewModels.Count; i++) { var filterViewModel = filterViewModels[i] as IFilterViewModel; if (i == filterViewModels.Count - 1) { ((DataSourceBase)PivotGrid.DataSource).ExpandToLevelAsync(filterViewModel, filterViewModel.Hierarchy.Levels.Count - 1).ContinueWith( (t) => PivotGrid.DataSource.RefreshGrid(), TaskContinuationOptions.ExecuteSynchronously); } else { ((DataSourceBase)PivotGrid.DataSource).ExpandToLevelAsync(filterViewModel, filterViewModel.Hierarchy.Levels.Count - 1); } }
##################
I used the word usually because in certain environments my application hangs on "PivotGrid.DataSource.RefreshGrid()" (hangs means doesn't respond to anything while having 0% CPU usage)
This occurs on 2 PCs with the same configuration:
HP Compaq Elite 8300 SFF
Intel Core i5-3570Win 7 32 bit
This Error occurs only when i try to expand all rows programmatically (using the "+"-indicators of the UI works as expected),
expanding single Nodes by Code (eg. when restoring a previous saved state of the grid) works flawlessly.
Does anyone have an Idea how to fix/avoid this? I really need this functionality...
BR
Hello,
How many hierarchies you operate with when this happen? Could you try to refresh grid once you have all nodes expanded. I mean if you collect the task objects which ExpandToLevelAsync return and then refresh the grid:
Task.Factory.ContinueWhenAll(tasks.ToArray(), t => PivotGrid.DataSource.RefreshGrid(), TaskContinuationOptions.ExecuteSynchronously);
Regards,Plamen.
Hello Plamen,
I'm operating with one Hierarchy with 4 Levels beneath, i attached 2 screenshots to illustrate what i'm doing.
The Code you provided me with didn't change that behaviour - As soon as RefreshGrid is called the Application stops.
BR,
Daniel
####
Hello Petar,
sorry for my misleading sample. This was just to demonstrate that even if you wait for the task (what makes this asynchron task kind of synchron) the RefreshGrid() is causing the program to freeze.
I've now tried your suggestions but they also have the same effect. Here is my original code, an extension method for the XamPivotGrid which I'm calling in my ViewModel classes not in code behind of the view:
public static void ExpandAllHeaders(this XamPivotGrid pivotGrid, Action callback = null)
{
var filterViewModels = pivotGrid.DataSource.Rows.Concat(pivotGrid.DataSource.Columns).Where(fvm => fvm is IFilterViewModel).ToList();
for (int i = 0; i < filterViewModels.Count; i++)
var filterViewModel = filterViewModels[i] as IFilterViewModel;
if (filterViewModel == null)
return;
if (i == filterViewModels.Count - 1)
EventHandler<ResultChangedEventArgs> handler = null;
handler = (sender, e) =>
pivotGrid.DataSource.ResultChanged -= handler;
if (callback != null)
callback();
};
pivotGrid.DataSource.ResultChanged += handler;
( (DataSourceBase)pivotGrid.DataSource ).ExpandToLevelAsync(filterViewModel, filterViewModel.Hierarchy.Levels.Count - 1)
.ContinueWith(t => { pivotGrid.DataSource.RefreshGrid(); }, System.Threading.Tasks.TaskContinuationOptions.ExecuteSynchronously);
}
else
( (
DataSourceBase)pivotGrid.DataSource ).ExpandToLevelAsync(filterViewModel, filterViewModel.Hierarchy.Levels.Count - 1);
When you have to expand multiple hierarchies my suggestion is to collect all your task objects in a list and call RefreshGrid() once all tasks are completed:
Task.Factory.ContinueWhenAll(tasks.ToArray(),
t => dataSource.RefreshGrid(), TaskContinuationOptions.ExecuteSynchronously);
I tried your suggestion but this also doesn't work. The problem is that RefreshGrid is called but freezes the application before ResultChanged event is fired.
I figured out how to reproduce the behavior. If you call my ExpandAll function with two pivot grids one after another the expanding works:
MyXamPivotGrid1.ExpandAll();
MyXamPivotGrid2.ExpandAll();
But if I'm using the callback as shown below it leads to the described freezing error:
MyXamPivotGrid1.ExpandAllHeaders(
() => MyXamPivotGrid2.ExpandAllHeaders());
But my Problem is that I have to use the callbacks to know when the expansion is finished and then start an excel export of the grids.
It would be nice if you could try to reproduce this with an own sample (Two filled pivot grids expanding with my function in callback).
As mentioned all worked before I upgraded to the new NetAdvantage Version 13.1. so could it be that your development team maybe changed something in the RefreshGrid method?
Regards
No answer?
Hello mwicke,
I have been looking into this for you and created a test sample to your specification (Pivot_tasks.zip) running under version 13.1. When I run it and press the expand button first the top XamPivotGrid’s Columns expand and then the bottom XamPivotGrid’s Columns expand too. I have attached the sample for your reference please let me know, if you can reproduce the behavior you described using it, or please modify it so it does.
Looking forward to hearing from you.