Hi,
I have a PivotGrid with data. I want to programmatically add rows/ cols/rows/measures. How can I do this?
For example, in the FlastDataSource, where do I add get cols to add to flastDataSource.Columns.Add(.??). Where can I get the list of columns available.
Thanks
Sangeetha
Hi Sangeetha,
Thanks very much. I’m sure it will be helpful to others
Sure Marianne. Here is the code I used:
private void SetPivotConfig(FlatDataSource flatDataSource, PivotConfig pivotConfig) { Dispatcher.BeginInvoke((Action)delegate() { try { flatDataSource.Columns.Clear(); flatDataSource.Rows.Clear(); flatDataSource.Measures.Clear(); pivotGrid.DataSource.DeferredLayoutUpdate = true; foreach (IDimension dim in pivotGrid.DataSource.Cube.Dimensions) { foreach (IHierarchy hierarchy in dim.Hierarchies) { if (pivotConfig.Rows.Contains(hierarchy.Caption)) { IFilterViewModel fvm = pivotGrid.DataSource.CreateFilterViewModel(hierarchy); pivotGrid.DataSource.Rows.Add(fvm); } else if (pivotConfig.Cols.Contains(hierarchy.Caption)) { IFilterViewModel fvm = pivotGrid.DataSource.CreateFilterViewModel(hierarchy); pivotGrid.DataSource.Columns.Add(fvm); } else if (pivotConfig.Filters.Contains(hierarchy.Caption)) { IFilterViewModel fvm = pivotGrid.DataSource.CreateFilterViewModel(hierarchy); pivotGrid.DataSource.Filters.Add(fvm); } } } foreach (IMeasure measure in pivotGrid.DataSource.Cube.Measures) { if (pivotConfig.Measures.Contains(measure.UniqueName)) { IMeasureViewModel mvm = pivotGrid.DataSource.CreateMeasureViewModel(measure); pivotGrid.DataSource.Measures.Add(mvm); } } pivotGrid.DataSource.DeferredLayoutUpdate = false; } catch (Exception e) { MessageBox.Show(e.Source + " " + e.Message); } }); }
HI Sangeetha,
Can you share your solution? It may be helpful to others who follow this thread.
Figured it out thanks.