Hi,
I am using CellControlAttached event in order to set the foreground color of the xampivotgrid cell as well as format the number. We display a number of products:
e.g. We show Product 1, Product 2 and Product 3 in the same pivot grid view. Out scenario is that we want negative numbers in red as well as format the number based on the product, so in the case of Product 1 we want 4 decimal places, Product 2 we want 2 decimals and Product 3 we want 1. Here is some code to demonstrate this example.
private void PivotGridCellControlAttached(object sender, PivotCellControlAttachedEventArgs e) { if (pivotGrid.DataSource == null) return; var rowIndex = pivotGrid.DataRows.IndexOf(e.Cell.DataRow); var columnIndex = pivotGrid.DataColumns.IndexOf(e.Cell.DataColumn); ICell cellData = pivotGrid.DataSource.Result.Cells[rowIndex, columnIndex]; if (cellData == null) return; var value = 0.0; if (!double.TryParse(cellData.Value.ToString(), out value)) return; Style s = null; if (value < 0) s = Resources["RedStyle"] as Style; if (e.Cell.Style == null || e.Cell.Style != s) e.Cell.Style = s; var itemsIndexes = myFlatDataSource.GetCellItemsIndexes(cellData); if (itemsIndexes.Count == 0) return; var record = myFlatDataSource.GetRecord(itemsIndexes[0]); if (record == null) return; var myObject = record as MyObjectType; var product = myObject.Product; if(product == "Product 1") cellData.SetValue(cellData.Value, null, "{0:0.0000}"); else if (product == "Product 2") cellData.SetValue(cellData.Value, null, "{0:0.00}"); else if (product == "Product 3") cellData.SetValue(cellData.Value, null, "{0:0.0}"); }
The RedStyle gets applied correctly to all the cells, but the number format gets applied to all values currently out of view. The cells displayed in my intial view only apply the format if i scroll the cell out of veiw and then scroll it back into view.
I am guessing that this is due to the virtualisation of the grid, could you let me know how i can get around it please.
Thanks,
Nick
I have also noticed that with PivotGridCellControlAttached being handled the scrolling responce of the grid has decreased dramatically when viewing a large result set. Is there a different approach i could take that would not have such an affect on performance.
Regards,Nick
Hello Nick,
I have been looking into this issue and I am not able to reproduce it, still I can suggest you set e.IsDirty=true which will prevent the controls from virtualization and may help in your scenario.
If after making this modification you are still able to reproduce the issue, would you please provide me with a small test sample, so I can research this further.
Thanks in advance.
Thank you for the sample. I have been looking into it and in order to format the values of the cells I can suggest you create a base style for the PivotCellControl and change the format of the cell trough it using converter. Similarly you can use this approach to change the foreground of the cells based on their value. Using converter you will not have to change the style every time the cell scroll into view by handling the CellControlAttached event. For further reference, please have a look at the attached sample, which I modified for you.
If you need any additional assistance on this, please do not hesitate to ask.
Hi Elena,
Thanks for the reply, i am attaching a sample app demonstrating the behaviour. I tried e.IsDirty = true; and it doesn't work either. As i mentioned earlier, is there another way to acheive the conditional formating demonstated in my sample app without using CellControlAttached as that really slows down the scrolling of the grid when it contains a lot of data. The Infragistics DV assebly version i am using is: 11.2.20112.1012