Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
3160
how to add displayformat in code?
posted

 

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.html
http://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);
        }

Parents
No Data
Reply
  • 8831
    posted

    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.

Children