I am trying to make a simple example with xamPivotGrid, but am not able to make it work.
The code uses a List, since the documentation states thatxamPivotGrid works with Lists.
List<testData> testList = new List<testData>(); testList.Add(new testData(1, 1, 1)); testList.Add(new testData(2, 2, 2)); testList.Add(new testData(3, 3, 3)); FlatDataSource flatDataSource = new FlatDataSource(); flatDataSource.ItemsSource = testList; flatDataSource.Cube = DataSourceBase.GenerateInitialCube("TestCube"); flatDataSource.Columns = DataSourceBase.GenerateInitialItems("[TimeID]"); flatDataSource.Rows = DataSourceBase.GenerateInitialItems("[AreaID]"); flatDataSource.Measures = DataSourceBase.GenerateInitialItems("[Measure]"); xamPivotGrid1.DataSource = flatDataSource; } public class testData { public int AreaID; public int TimeID; public float Measure; public testData(int AID, int TID, float Meas) { AreaID = AID; TimeID = TID; Measure = Meas; } }
Hi Plamen
Thanks, that did resolved the issue.
List<testData> testList = new List<testData>();testList.Add(new testData(1, 1, 1));testList.Add(new testData(2, 2, 2));testList.Add(new testData(3, 3, 3));FlatDataSource flatDataSource = new FlatDataSource();flatDataSource.ItemsSource = testList;//flatDataSource.Cube = DataSourceBase.GenerateInitialCube("TestCube");flatDataSource.Columns = DataSourceBase.GenerateInitialItems("[TimeID].[TimeID]");flatDataSource.Rows = DataSourceBase.GenerateInitialItems("[AreaID].[AreaID]");flatDataSource.Measures = DataSourceBase.GenerateInitialItems("Measure");xamPivotGrid1.DataSource = flatDataSource;dataGrid1.ItemsSource = testList;}public class testData{public int AreaID { get; set; }public int TimeID { get; set; }public float Measure { get; set; }public testData(int AID, int TID, float Meas){AreaID = AID;TimeID = TID;Measure = Meas;}}
I will now try the next step and use more advanced stuff.
Hi Peter,
I've just seen you're using public fields instead of using properties:
public class testData
{
public int AreaID { get; set; }
public int TimeID { get; set; }
public float Measure { get; set; }
public testData(int AID, int TID, float Meas)
AreaID = AID;
TimeID = TID;
Measure = Meas;
}
Also something I've missed is that the measure name has no square brackets:flatDataSource.Measures = DataSourceBase.GenerateInitialItems("Measure");
Plamen.
Hi Plamen,
Thanks for your suggestions. I tried it and also removed GenerateInitialCube statement.
The list and flatdatasource.itemssource have elements, but nothing is shown on the UI.
Do you have other suggestions?
Peter
Hello Peter,
Could you try to init it in this way:
flatDataSource.Cube = DataSourceBase.GenerateInitialCube("testData");flatDataSource.Columns = DataSourceBase.GenerateInitialItems("[TimeID].[TimeID]");flatDataSource.Rows = DataSourceBase.GenerateInitialItems("[AreaID].[AreaID]");flatDataSource.Measures = DataSourceBase.GenerateInitialItems("[Measure]");
Also using DataSourceBase.GenerateInitialCube is optional, however if it's used the parameter value should be the name of the type used by the items source.