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
305
Getting flat data source to work with xamPivotGrid
posted

Hi,

I spent all day trying to find the answer and failed, so here's the question. I have a flat datasource that I'd like to show in xamPivotGrid. I tried a number of ways but for simplicity here it is.

    public class Data {
        public DateTime Date { get; set; }
        public string Ticker { get; set; }
        public string Ticker2 { get; set; }
        public double Value { get; set; }
    }

  public override void OnDataLoaded() {

            List<Data> data = new List<Data>();
            data.Add(new Data {
                Date = DateTime.Parse("1/1/2000"),
                Ticker = "IBM",
                Ticker2 = "MSFT",
                Value = 1.0
            });

            data.Add(new Data {
                Date = DateTime.Parse("1/1/2000"),
                Ticker = "AEE",
                Ticker2 = "YSI",
                Value = 2.0
            });

            FlatDataSource flatDataSource = new FlatDataSource {
                ItemsSource = data,
                Cube = DataSourceBase.GenerateInitialCube("Data"),
                Rows = DataSourceBase.GenerateInitialItems("[Date]"),
                Columns = DataSourceBase.GenerateInitialItems("[Ticker],[Ticker2]"),
                Measures = DataSourceBase.GenerateInitialItems("Value")
            };

            flatDataSource.RefreshGrid();

            PivotDataSource = flatDataSource;
            NotifyPropertyChanged("PivotDataSource");
}

The code above resides in the ViewModel. DataSource property of the grid and the selector is bound to PivotDataSource property of the ViewModel.

The code works and I get the values in the grid but I can't figure out how not to use the selector to select the rows and columns but do it programatically (preferably once and for all). Any advice?

Thank you,

Gene