Skip to main content

Remove Data Providers from the Report Wizard

  • 3 minutes to read

This example illustrates how to remove some of the data providers available on the Specify a Connection String wizard page.

The following image illustrates this wizard page with all the data providers removed except for Microsoft SQL Server.

report-wizard-select-data-provider-customize

Use one of the following approaches to customize the Data Source and Report wizard pages.

Customize the Wizard at Design Time

To customize the Data Source and Report wizard pages at design time in the Visual Studio, drop the StandardReportDesigner or RibbonReportDesigner control on a form and select the XRDesignMdiController component.

In the Properties window, expand the XRDesignMdiController.SqlWizardSettings property and select the required data providers in the SqlWizardSettings.AvailableDataProviders property editor.

SqlWizardSettings-AvailableDataProviders

Customize the Wizard in Code

To customize the Data Source and Report wizard pages in code, do the following.

  1. Add a custom service implementing the IWizardCustomizationService interface.

    The following codes removes the Select the Data Source Type wizard page by enabling only the DataSourceType.Xpo setting (corresponding to the Database Connection option).

    Then, the CustomizeProviders<TModel> method is called which assigns a custom list of data providers to a corresponding ISqlDataSourceModel object.

    using DevExpress.DataAccess.Native.Sql.ConnectionStrategies;
    using DevExpress.DataAccess.UI.Wizard;
    using DevExpress.DataAccess.Wizard.Model;
    using DevExpress.DataAccess.Wizard.Presenters;
    using DevExpress.XtraReports.Wizards;
    using DevExpress.XtraReports.Wizards.Presenters;
    using System.Collections.Generic;
    using System.ComponentModel.Design;
    // ...
    
    class MyWizardCustomizationService : IWizardCustomizationService {
        #region Implementation of IWizardCustomizationService
    
        void IWizardCustomizationService.CustomizeReportWizard(IWizardCustomization<XtraReportModel> tool) {
            if (tool.StartPage == typeof(ChooseReportTypePage<XtraReportModel>)) {
                tool.Model.ReportType = ReportType.Standard;
                tool.Model.DataSourceType = DataSourceType.Xpo;
                tool.StartPage = typeof(ConnectionPropertiesPage<XtraReportModel>);
            }
            CustomizeProviders(tool);
        }
    
        void IWizardCustomizationService.CustomizeDataSourceWizard(IWizardCustomization<XtraReportModel> tool) {
            if (tool.StartPage == typeof(ChooseDataSourceTypePage<XtraReportModel>)) {
                tool.Model.DataSourceType = DataSourceType.Xpo;
                tool.StartPage = typeof(ConnectionPropertiesPage<XtraReportModel>);
            }
            CustomizeProviders(tool);
        }
    
        bool IWizardCustomizationService.TryCreateDataSource(IDataSourceModel model, out object dataSource, out string dataMember) {
            dataSource = null;
            dataMember = null;
            return false;
        }
    
        bool IWizardCustomizationService.TryCreateReport(IDesignerHost designerHost, XtraReportModel model, object dataSource, string dataMember) {
            return false;
        }
    
        #endregion
    
        static void CustomizeProviders<TModel>(IWizardCustomization<TModel> tool) where TModel : ISqlDataSourceModel {
            List<ProviderLookupItem> providers = (List<ProviderLookupItem>)tool.Resolve(typeof(List<ProviderLookupItem>));
            providers.RemoveAll((ProviderLookupItem x) => x.ProviderKey != "MSSqlServer");
        }
    }
    
  2. Register the created service by calling the XRDesignMdiController.AddService method.

    using DevExpress.XtraReports.Wizards;
    // ...
    
    namespace WindowsFormsApplication1 {
        public partial class frmDesigner : System.Windows.Forms.Form {
            public frmDesigner() {
                InitializeComponent();
                reportDesignerMDIController.AddService(typeof(IWizardCustomizationService), new MyWizardCustomizationService());
                Load += FrmDesigner_Load;
            }
    
            void FrmDesigner_Load(object sender, System.EventArgs e) {
                reportDesignerMDIController.CreateNewReportWizard();
            }
        }
    }
    
See Also