All docs
V19.2
19.2
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.

Register Types for Object Data Source Wizard

  • 5 min to read

This topic describes how to make object types available in the Report Wizard and Data Source Wizard, and allow users to create an Object Data Source.

Declare Data Types

Declare a class that provides data.

  • Declare fields in the class. These fields provide data when users select Entire Object in the Report Wizard and Data Source Wizard.
  • Declare methods that return IEnumerable<T> values. Users can select one of these methods in the Report Wizard and Data Source Wizard to provide data to reports.

The Report Wizard and Data Source Wizard use class namespace and name to list types. Apply the DisplayName attribute to a class to specify a custom display name.

DisplayName is Not Applied DisplayName is Applied
DisplayName - Before DisplayName - After
using System;
using System.Collections.Generic;
using System.ComponentModel;

namespace WebForms.SampleObjectTypes {
    [DisplayName("My Data Source")]
    public class DataSource {
        List<DataItem> data = new List<DataItem>();
        public DataSource() : this(100) { }
        public DataSource(int count) : this(count, 1000) { }
        public DataSource(int count, int maxValue) {
            var random = new Random();
            for(var i = 0; i < count; i++) {
                data.Add(new DataItem() {
                    Random = random.Next(0, maxValue)
                });
            }
        }
        public List<DataItem> GetData() {
            return data;
        }

        public List<DataItem> GetData(int count) {
            return data.GetRange(0, count);
        }
    }

    public class DataSource2 : DataSource {
        public DataSource2() : base(1000, 1000) { }
    }
    public class DataItem {
        public int Random { get; set; }
    }
}

Register the Declared Types

Implement the IObjectDataSourceWizardTypeProvider interface. Return the type list in the GetAvailableTypes(String) method.

using System;
using System.Collections.Generic;
using DevExpress.DataAccess.Web;
// ...
public class CustomObjectDataSourceWizardTypeProvider : IObjectDataSourceWizardTypeProvider {
    public IEnumerable<Type> GetAvailableTypes(string context) {
        return new[] {
            typeof(SampleObjectTypes.DataSource),
            typeof(SampleObjectTypes.DataSource2)
        };
    }
}

Call the RegisterObjectDataSourceWizardTypeProvider<T>() method at the application's startup to register the class that implements the interface. This applies the type list in the Report Wizard and Data Source Wizard.

using DevExpress.XtraReports.Web;
using WebForms.Services;
// ...
DevExpress.XtraReports.Web.ReportDesigner.DefaultReportDesignerContainer.RegisterObjectDataSourceWizardTypeProvider<CustomObjectDataSourceWizardTypeProvider>();

list-types

Filter Type Constructors

The Report Wizard and Data Source Wizard list all constructors declared in the registered types and allow users to choose any constructor to create an object data source. Implement the IObjectDataSourceConstructorFilterService interface to filter constructors.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using DevExpress.DataAccess.Web;
// ...
public class CustomObjectDataSourceConstructorFilterService : IObjectDataSourceConstructorFilterService {
    public IEnumerable<ConstructorInfo> Filter(Type dataSourceType, IEnumerable<ConstructorInfo> constructors) {
        if(dataSourceType == typeof(SampleObjectTypes.DataSource2)) {
            return constructors;
        }
        return constructors.Where(x => x.GetParameters().Length > 0);
    }
}

Call the RegisterObjectDataSourceConstructorFilterService<T>() method at the application's startup to register the class that filters constructors.

using DevExpress.XtraReports.Web;
using WebForms.Services;
// ...
DevExpress.XtraReports.Web.ReportDesigner.DefaultReportDesignerContainer.RegisterObjectDataSourceConstructorFilterService<CustomObjectDataSourceConstructorFilterService>();
Constructors are Not Filtered Constructors are Filtered
Filter-Constructors-Before Filter-Constructors-After

Filter Type Members

The Report Wizard and Data Source Wizard list all IEnumerable<T> members declared in the registered types and allow users to choose any member to provide data. Implement the IObjectDataSourceMemberFilterService interface to filter members.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using DevExpress.DataAccess.Web;
// ...
public class CustomObjectDataSourceMemberFilterService : IObjectDataSourceMemberFilterService {
    public IEnumerable<MemberInfo> Filter(Type dataSourceType, IEnumerable<MemberInfo> members) {
        if(dataSourceType == typeof(SampleObjectTypes.DataSource2)) {
            return members;
        }
        return members.Where(x => {
            var method = x as MethodInfo;
            if(method != null) return method.GetParameters().Length > 0;
            return false;
        });
    }
}

Call the RegisterObjectDataSourceMemberFilterService<T>() method at the application's startup to register the class that filters members.

using DevExpress.XtraReports.Web;
using WebForms.Services;
// ...
DevExpress.XtraReports.Web.ReportDesigner.DefaultReportDesignerContainer.RegisterObjectDataSourceMemberFilterService<CustomObjectDataSourceMemberFilterService>();
Members are Not Filtered Members are Filtered
Filter-Members-Before Filter-Members-After