Dear All,
I am not able to bind a FlatDataSource to the DataSource property of XamPivotGrid.
When I try to assign it manually I am getting this error:
"'Infragistics.Olap.FlatData.FlatDataSource' is not a valid value for property 'DataSource'."
I also include the function that has been used.
/// <summary>
/// Set the datasource as a datatable
/// The row, column, and measure pivot fields are assumed to be
/// RowPivot, ColumnPivot, Measure respectively
/// </summary>
/// <param name="dt"></param>
public void SetFlatDatasource(DataTable dt, string reportName)
{
BuildDataSource(dt, reportName);
}
/// Set the flat data source when the data source is a datatable
private void BuildDataSource(DataTable dt, string reportName)
DynamicTypeBuilder typeBuilder = new DynamicTypeBuilder
DynamicAssemblyName = "Assembly",
DynamicTypeName = "Pane"
};
IList<DynamicTypePropertyInfo> properties = new List<DynamicTypePropertyInfo>();
foreach (DataColumn column in dt.Columns)
DynamicTypePropertyInfo propertyInfo = new DynamicTypePropertyInfo
PropertyName = column.ColumnName,
PropertyType = column.DataType
properties.Add(propertyInfo);
Type dynamicType = typeBuilder.GenerateType(properties);
Type listType = typeof(List<>);
Type genericListType = listType.MakeGenericType(dynamicType);
IList list = (IList)Activator.CreateInstance(genericListType);
foreach (DataRow dataRow in dt.Rows)
object myDynamicInstance = Activator.CreateInstance(dynamicType);
PropertyInfo propertyVal = dynamicType.GetProperty(column.ColumnName);
if (dataRow[column] != DBNull.Value)
propertyVal.SetValue(myDynamicInstance, dataRow[column], null);
list.Add(myDynamicInstance);
FlatDataSource flatDataSource = new FlatDataSource
DimensionsGenerationMode = DimensionsGenerationMode.Property,
ConnectionSettings = new FlatDataConnectionSettings(),
Cube = DataSourceBase.GenerateInitialCube("Pane"),
Columns = DataSourceBase.GenerateInitialItems(GetPivotColumns(reportName)),
Rows = DataSourceBase.GenerateInitialItems(GetPivotRows(reportName)),
Measures = DataSourceBase.GenerateInitialItems(GetPivotData(reportName))
// Set the hierarchy levels for date time fields
HierarchyDescriptor dateTimeDescriptor = new HierarchyDescriptor { AppliesToPropertiesOfType = typeof(DateTime) };
dateTimeDescriptor.AddLevel<DateTime>(dateTime => dateTime.MonthShort(), "Months");
dateTimeDescriptor.AddLevel<DateTime>(dateTime => dateTime.ToShortDateString(), "Dates");
flatDataSource.AddHierarchyDescriptor(dateTimeDescriptor);
// Need to set the item source after the hierarchy descriptor
flatDataSource.ItemsSource = list;
PivotGrid.DataSource = flatDataSource;
// FlatDataSource = flatDataSource;
Hello Murat,
Thank you for your post. I have been looking into it and, but there are methods which you use and you doesn’t include in the code snippet, so could you please send an isolated sample project, where the issue is reproduced, so I can investigate it further for you.
Looking forward for your reply.
Hello Stefan,
It turns out that I was using a wrong version off FlatDataSource dll. When I used the appropriate dll, issue is resolved.
Best Regards,
Murat.
Thank you for your feedback. I am glad that you resolved your issue and I believe that other community members may benefit from this as well.
Thanks again.