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
XamPivotGrid FlatDataSource Binding Issue
posted

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);

        }

 

        /// <summary>

        /// Set the flat data source when the data source is a datatable

        /// </summary>

        /// <param name="dt"></param>

        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);

                foreach (DataColumn column in dt.Columns)

                {

                    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;

 

        }

 

 

/// <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);

        }

 

        /// <summary>

        /// Set the flat data source when the data source is a datatable

        /// </summary>

        /// <param name="dt"></param>

        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);

                foreach (DataColumn column in dt.Columns)

                {

                    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;

 

        }