I need to add displayFormat to my measure in code as shown below. Unfortunately it doesnt work....What am I doing wrong?The displayformat is correct when the measure is quantity but not when the measure is PctMktValue
http://help.infragistics.com/Help/NetAdvantage/WPFDV/2011.1/CLR4.0/html/xamPivotGrid_US_Defining_Hierarchies_And_Providing_Metadata_With_FlatData.htmlhttp://community.infragistics.com/forums/t/69498.aspx
private void OnMeasureChanged(object sender, RoutedEventArgs e) { RadioButton radio = sender as RadioButton; ExposureGrid.DataSource.Measures.Clear(); FilterHelper.FlatDataSource.CubesSettings.Clear(); ExposureGrid.LayoutLoaded += new EventHandler<EventArgs>(ExposureGrid_LayoutLoaded); ViewModel.IsQuantityView = radio.Content.ToString() == "Quantity"; string measureName = "Qty"; string displayformat = "{}{0:#,#;(#,#)}";
if (!ViewModel.IsQuantityView) { measureName = "PctMktValue"; displayformat = "{}{0:#,#.##%;(#,#.##)%}"; // dosnt work } IMeasureViewModel measure = ExposureGrid.DataSource.CreateMeasureViewModel(ExposureGrid.DataSource.Cube.Measures[measureName]); DimensionMetadata dmd = new DimensionMetadata { DisplayFormat = displayformat, SourcePropertyName = measureName }; CubeMetadata cmd = new CubeMetadata {DataTypeFullName = typeof(ExposureItem).FullName }; cmd.DimensionSettings.Add(dmd); ExposureGrid.DataSource.Measures.Add(measure); ((FlatDataSource)ExposureGrid.DataSource).CubesSettings.Add(cmd); }
Hi Sam,
Once FlatDataSource is initialized its metadata can't be changed anymore. I'm not sure at which point your code is called. Since it looks that measures' format for your application is conditional, you can modify FlatMeasure.DisplayFormat when you need anytime later:
FlatMeasure measure = flatDataSource.Cube.Measures.
FirstOrDefault(m => m.Caption == "MyMeasure1") as FlatMeasure;
if (measure != null)
{
measure.DisplayFormat = "{0:C3}";
}
Also you need to remove the first two curly brackets (highlighted below) used as escaping characters when such string is passed in XAML.
displayformat = "{}{0:#,#.##%;(#,#.##)%}"; // dosnt work
Regards.Plamen.
Hi Plamen, the code I posted is called in the event handler of a radio button that allows the user to select what measure is displayed on the grid. I handle the layout loaded event I supposed I could put something there?
In any case the code you posted does not build, sorry:
DisplayFormat is not a property of FlatMeasure.
Did you have the latest SR of v11.2? It was delivered a week ago.
Plamen, we are using 11.2 and it does not work.. Unfortunately we cant change versions.
The FlatMeasure.DisplayFormat is available in version v11.2 and above. Would it be a problem if you try to use a newer version? Also please note that there will be no future SR for v11.1 anymore.
Plamen.