How to: Create a Custom Button in the Dashboard Title to Load Data on Demand

This example demonstrates how to load data in the Dashboard designer on demand when all the required filters are set. Currently, the designer reloads data after filter elements are changed. This reduces the performance in case of large amounts of data. The following approach allows you to select filter values without any loaded data and subsequently click the Show Data button in the dashboard title to load and display filtered data.

Start with a sample dashboard designer application created using the DevExpress Template Gallery.

  1. Run the project.
  2. Add the List Box filter element to a dashboard, set its Dimension to the State column and arrange dashboard items as illustrated below.

  3. Create a new dashboard parameter by clicking Parameters in the Dashboard group on the Home ribbon tab. In the invoked Parameters dialog, add a new boolean parameter named ShowData.

  4. To create a filter for the Product Units Sold grid dashboard item, click Filter in the Filtering group on the Data ribbon tab. Use the Filter Editor to specify criteria as illustrated in the image below.

    The Product Units Sold dashboard item displays data only when the ShowData parameter is true.

  5. Save the dashboard definition in an XML file, stop the application and open the project in Visual Studio.

  6. Add the code that handles the CustomizeDashboardTitle event to create a push button which triggers the ShowData parameter.

    Note

    The complete sample project WinForms Dashboard - How to delay data load until all filters are set is available in the DevExpress Examples repository.

    using DevExpress.DashboardWin;
    using System;
    using System.Linq;
    
    namespace CustomShowDataExample
    {
        public partial class DesignerForm1 : DevExpress.XtraBars.Ribbon.RibbonForm
        {
            public DesignerForm1()
            {
                InitializeComponent();
                dashboardDesigner.CustomizeDashboardTitle += DashboardDesigner_CustomizeDashboardTitle;
                dashboardDesigner.LoadDashboard(@"..\..\Dashboards\dashboard1.xml");
            }
    
            #region #CustomizeDashboardTitle
            private void DashboardDesigner_CustomizeDashboardTitle(object sender, DevExpress.DashboardWin.CustomizeDashboardTitleEventArgs e)
            {
                DevExpress.Data.IParameter showDataParameter = dashboardDesigner.Parameters.FirstOrDefault(p => p.Name == "ShowData");
                if (showDataParameter != null)
                {
                    bool showData = (bool)showDataParameter.Value;
                    DashboardToolbarItem showDataItem = new DashboardToolbarItem(showData, "Select states in the State list box and click this button to display data",
                        new Action<DashboardToolbarItemClickEventArgs>((args) => {
                            showDataParameter.Value = !showData;
                        }));
                    showDataItem.Caption = "Show Data";
                    showDataItem.SvgImage = svgImageCollection1[0];
                    e.Items.Insert(0, showDataItem);
                }
            }
            #endregion #CustomizeDashboardTitle
        }
    }
    
  7. Run the application, check values in the States list box and click the Show Data button to load the data.