Hi,
I am trying to format data dynamically, by allowing user to choose date format from context menu. The following is the event handler I use. When I debug I see that FlatDataSource is updated, but for some reason the grid is not updated. Could you please tell me what I am doing wrong. Or is this a bug?? Refreshing the grid doesn't seem to help.
private void QuickDates_Click(object sender, RoutedEventArgs e) { if (pivotGrid.DataSource != null) { MenuItem mi = sender as MenuItem; string dateFormat = mi.Header as string; FlatDataSource flatDataSource = pivotGrid.DataSource as FlatDataSource; int index = 0; foreach (DimensionMetadata metaData in flatDataSource.CubesSettings[0].DimensionSettings) { if (metaData.SourcePropertyName.Equals("End Date")) { flatDataSource.CubesSettings[0].DimensionSettings[index++].DisplayFormat = dateFormat; //metaData.DisplayFormat = dateFormat; break; } index++; } } }
Thanks
Sangeetha
Hello,
Currently such functionality is not supported and these settings are used only when the control is initialized.
Regards.Plamen.
Thank You Plamen.
Is there an alternative to this?
Hello Sangeetha,
Excuse me for the late reply. I have been looking into your issue for some time now and finally managed to come up with a custom approach that does what you want. I have put it into a sample project you can test out (PivotGrid_2.zip) where I have used a MultiValueConverter which would detect the different ContextMenu selections.
Please look through the sample and let me know if you require any further clarification on the matter.
My problem is, I set the Style in LayoutUpdated (as I need to set it only for a specific column), so when the Converter is executed, LayoutUpdated is fired again - so it goes into an infinite loop.
If I can find a better event to set the style in, my problem would be resolved.
Excuse me for the confusion I have spent some more time looking for a solution on your issue and think this I time I nailed it. I managed to use the CellControlAttached event to filter through the data cells and apply the formatting style from my previous sample only to those that meet a certain criteria. In the sample project I have created for you initially there are two measures loaded in the XamPivotGrid and I check and apply my Style only to the ones that come from the “Cost” measure. Also there is a ComboBox in the top right corner which SelectedItem sets a format for the “Cost” measure data cells dynamically thanks to a MultiBinding I used in the “CellStyle” style.
Please look through your sample project (PivotGrid_formatting_data.zip) and let me know if you require any further clarification on this custom approach.
Hi Peter,
I am sorry I was not clear in my question. I need to format PivotHeaderCells and not PivotCells.
Unfortunately CellControlAttached does not solve my problem as it only applied to PivotCells and not PivotHeaderCells.
I would be nice to have CellControlAttached event apply to both PivotCells and PivotHeaderCells. Or atleast have a similar event for PivotHeaderCells.
Hi again,
Please attach a descriptive screenshot of a XamPivotGrid and mark the PivotGridCells you feel are in one column.
Looking forward to hearing from you.
Hi Petar,
Replacing IValueConverter with IMultiValueConverter did the trick. It works perfectly now.
Hi Sangeetha,
You can see how I have managed to get the format to come from the ComboBox in the top right corner through the binding in the sample I last sent. I used a MultiValueConverter in order to have a non-static format value. Now since the binging comes from it and from the cell values if there is a change in any of those the values are reconfigured.
Please let me know if you require any further clarification on the matter.
Thank You for your great solution. I used it to figure out what was wrong with mine - it works perfectly now. I had been setting the style to the PivotHeadercellControl instead of the PivotHeaderCell itself. Setting it to the PivotHeaderCell does not fire LayoutUpdated when the format is updated.
There is one other small thing that needs to be fixed. Right now I hardcode the format in the converter. I would like to set this format through the Converter's parameter. In other words I want to see the format coming through in the following function. How can I do this?
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{ }
Here is a new sample approach (PivotGrid_formatting_HeaderCells.zip). Please look into it and let me know if this is what you were looking for.
In the image below, I want to format the PivotHeaderCells in PivotHeaderColumn EndDate dynamically.