Hi,
I get the following exception when I expand rows by calling the below mentioned function after I set the DataSource to the PivotGrid. Looks like some internal bug in PivotGrid.
Message: Object reference not set to an instance of an object.
Source: InfragisticsWPF4.Olap.v11.1
Stack Trace: at Infragistics.Olap.DataSourceBase.SwitchAxisMember(IMember axisMember) at Infragistics.Olap.FlatData.FlatDataSource.SwitchAxisMember(IMember axisMember) at Infragistics.Controls.Grids.PivotHeaderCell.set_IsExpanded(Boolean value) at MarketManipulatorControl.GridView.ExpandPivotGridColumns()
private void ExpandPivotGridColumns() { try { // Expand Column Hierarchy foreach (PivotColumnHeaderCell cell in pivotGrid.GridLayout.ColumnHeaderCells) { if (cell.IsToggleVisible && cell.IsExpanded == false) { cell.IsExpanded = true; return; } } // Expand Row Hierarchy foreach (PivotRowHeaderCell cell in pivotGrid.GridLayout.RowHeaderCells) { if (cell.IsToggleVisible && cell.IsExpanded == false) { cell.IsExpanded = true; return; } } } catch (Exception e) { } }
Is there any workaround for this?
Thanks
Sangeetha
If you call ExpandPivotGridColumns() method before there are any rendered columns/rows it is possible to get this exception. So can you provide us a sample ?
Here is how I use it:
DataTable dt = _marketData.GetMarketDataFor(selectedIndexes, DatasetType, ClosingDate, ""); if (dt != null) { // Set data to Data Grid, Pivot Grid and Pivot Grid Selector igGrid.DataSource = dt.DefaultView; FlatDataSource flatDataSource = DataConverter.ConvertDataTableToFlatDataSource(dt); flatDataSource.Columns = DataSourceBase.GenerateInitialItems("[Index Name].[Index Name]"); flatDataSource.Rows = DataSourceBase.GenerateInitialItems("[End Date].[End Date],[Gpt Name].[Gpt Name]"); flatDataSource.Measures = DataSourceBase.GenerateInitialItems("Effective Bid"); flatDataSource.Cube = DataSourceBase.GenerateInitialCube("Input"); pivotGrid.DataSource = flatDataSource; pivotGrid.DataSource.RefreshGrid(); pivotDataSelector.DataSource = flatDataSource; ExpandPivotGridRowsAndColumns();
I kind of suspected that the rows/cols were not rendered yet as you suggested. So I used the following code instead and it worked fine.
private void OnPivotGrid_ResultChanged(object sender, AsyncCompletedEventArgs e) { var dataSource = pivotGrid.DataSource; if (dataSource != null) { IResult result = dataSource.Result; if (result != null) { if (!_axisExpansionChangedManually) { IResultAxis axis = dataSource.Result.RowAxis; if (axis != null) { IMember firstRowMember = axis.Tuples.First().Members.First(); if (firstRowMember.Members.Count != 0) dataSource.SwitchAxisMember(firstRowMember); // expand the first row hierarchy, if it exists } } _axisExpansionChangedManually = false; }