Hi,
I would like to create a method that converts an arbitrary DataTable into a FlatDataSource.
What I have now is
public static FlatDataSource ToDataSource(this DataTable dt) { var flatDataSource = new FlatDataSource() { //http://blogs.infragistics.com/forums/p/46138/248517.aspx ItemsSource = dt.ToDynamicList(), Cube = DataSourceBase.GenerateInitialCube("Pane"), Columns = DataSourceBase.GenerateInitialItems("[Columns]"), Rows = DataSourceBase.GenerateInitialItems("[Row]"), Measures = DataSourceBase.GenerateInitialItems("Value") }; var cubeMetadata = new CubeMetadata(); flatDataSource.CubesSettings.Add(cubeMetadata); foreach (DataColumn col in dt.Columns) { //heirarchy var hier = new HierarchyDescriptor { SourcePropertyName = col.ColumnName, }; var allLevel = new HierarchyLevelDescriptor { LevelName = "All " + col.ColumnName + "s" }; var entriesLevel = new HierarchyLevelDescriptor { LevelName = col.ColumnName, LevelExpressionPath = col.ColumnName }; hier.LevelDescriptors.Add(allLevel); hier.LevelDescriptors.Add(entriesLevel); flatDataSource.HierarchyDescriptors.Add(hier); if (col.DataType == typeof(double)) { //NOTE: This doesn't work var dm = new DimensionMetadata() { SourcePropertyName = col.ColumnName, DisplayName = col.ColumnName, DimensionType = DimensionType.Measure, AggregatorType = AggregatorType.Sum, DisplayFormat = "{0:N2}" }; cubeMetadata.DimensionSettings.Add(dm); } } return flatDataSource; }
How can I get the measures to be formatted eg 0.00?
It seems like I had to set FlatDataSource.DimensionsGenerationMode
DLVendor, I am running into the same issue with the formatting not working. Could you post the final working version of your code, including the ToDynamicList function?
ToDynamicList
Hello DLVendor,
I am really glad that you manage to resolve your issue. If you still have any additional questions on this matter please do not hesitate to ask.