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?
HI Mwicke,
Here a link for 12.2
http://help.infragistics.com/NetAdvantage/WPF/Current/CLR4.0/?page=xamPivotGrid_US_Expanding_Hierarchies_In_Runtime_From_Code.html
Sincerely, Matt Developer Support Engineer
Thanks, but I don't see any changes to the link I posted. The problem is this solutions don't seem to work because I want to expand all dimensions in a method in my viewmodel not in an event in codebehind (as far as possible). This is the same method where in the next step I'm looping PivotGrid.GridLayout.RowHeaderCells but they are just containing the first row header. So there is no user interaction like clicking in the grid other than clicking an excel export button.
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
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,
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
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!