Hello,
I'm using a XamPivotTable (NetAdvantage 12.2) and need to expand all hierarchies/dimensions before an Excel export. Otherwise the values others than level 1 aren't loaded and can not be exorted! I tryed this one, but it doesn't worked: http://help.infragistics.com/Help/NetAdvantage/WPFDV/2011.1/CLR4.0/html/xamPivotGrid_US_Expanding_Hierarchies_In_Runtime_From_Code.html#seealsobookmark
Could you tell me how I can achieve this?
P.S.: I changed the part of the ResultChanged-Event and derigistered it after first usage, because otherwise it was called multiple times.
handler = (sender, e) => { pivotGrid.DataSource.ResultChanged -= handler; if(callback != null) callback(); }; pivotGrid.DataSource.ResultChanged += handler;
This seems to work, thank you very much!
Hi Mwicke,
After the hierarchies have been expanded, it takes some time to construct the new result and update the grid layout. I suggest that after you begin expanding the last hierarchy you attach an event handler for the ResultChanged event of the data source and execute your code there:
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 (i == filterViewModels.Count - 1) { dataSource.ResultChanged += (s, e) => { // do your work now var cellsCount = pivotGrid.GridLayout.RowHeaderCells.Count; }; ((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); } }
Let me know if this fixes your problem.
Philip
This still doesn't work quite correct. I can see that the dimensions get expanded. But RowHeaderCells.Count in code is still 1.
Hi Mwicke!
In 12.2 the DataSourceBase method exposes methods for expanding and collapsing a hierarchy to a specified level depth. I suggest you try the following:
foreach (var areaItemViewModel in pivotGrid.DataSource.Rows.Concat(pivotGrid.DataSource.Columns)) { var filterViewModel = areaItemViewModel as IFilterViewModel; if (filterViewModel != null) { ((DataSourceBase)pivotGrid.DataSource).ExpandToLevelAsync(filterViewModel, filterViewModel.Hierarchy.Levels.Count - 1).ContinueWith( (t) => pivotGrid.DataSource.RefreshGrid(), System.Threading.Tasks.TaskContinuationOptions.ExecuteSynchronously); } }
Best,Philip