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
Hi Petar,
Thank you for reply.
You misunderstood my question. I do not want different data cells to have different formats. I just want to format all rows of a Column (of type DateTime) dynamically.
My Converter seems to be working fine - I debugged it and the right values are returned by Convert(...). I just don't see the formats coming through in the Grid.
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.
Why can't I use the approach in the following link where a Style is set for each cell and a converter is defined:
http://blogs.infragistics.com/forums/p/49331/297530.aspx
The only problem is, my converter does not seem to be working properly. Could you please tell me what I am doing wrong?
Here is my code:
My converter:
public class PivotGridDateConverter : IValueConverter { #region IValueConverter Members public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { string formattedDate = ""; if (value != null) { try { IMember member = value as Member; DateTime dateTime = DateTime.Parse(member.Caption); formattedDate = dateTime.ToString("dd-MMM-yyyy"); } catch (Exception e) { Microsoft.Windows.Controls.MessageBox.Show(e.Message); } } return formattedDate; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return ""; } #endregion }
Here is the template I use in my style
<local:PivotGridDateConverter x:Key="DateConverter" /> <DataTemplate x:Key="DateTemplate" > <StackPanel Orientation="Horizontal"> <TextBlock Name="dateCellPresenter" Text="{Binding Converter={StaticResource DateConverter}}" /> </StackPanel> </DataTemplate>
<local:PivotGridDateConverter x:Key="DateConverter" /> <DataTemplate x:Key="DateTemplate" > <StackPanel Orientation="Horizontal"> <TextBlock Name="dateCellPresenter" Text="{Binding Converter={StaticResource DateConverter}}" /> <!-- <Hyperlink Click="Hyperlink_Click" Command="{Binding DataContext.MyCommand, RelativeSource={ RelativeSource FindAncestor, AncestorType ={x:Type ig:XamPivotGrid}}}"> <TextBlock Text="{Binding}" /> </Hyperlink> --> </StackPanel> </DataTemplate>
I have been looking into your issue and there doesn’t seem to be a built-in functionality for that at this time. If you want I can create a Feature Request on your behalf so this can appear in a future release of ours.
Looking forward to hearing from you.