Skip to main content

DashboardDesigner.SetMasterFilter(String, Object) Method

Selects required elements by their values in the specified master filter item.

Namespace: DevExpress.DashboardWin

Assembly: DevExpress.Dashboard.v24.2.Win.dll

Declaration

public void SetMasterFilter(
    string dashboardItemName,
    object values
)

Parameters

Name Type Description
dashboardItemName String

A String that specifies the component name of the master filter item.

values Object

Values that will be used to select elements in the master filter item.

Remarks

Note

The method fires the InvalidOperationException if master filtering is disabled in the specified dashboard item (the MasterFilterMode property is set to None). The exception message text is a localizable string which can be obtained by the MessageInteractivityOperationNotAvailable identifier.

Example

The following example demonstrates how to set master filter in the Dashboard Viewer control.

The Dashboard Viewer control loads a dashboard with two master filter items - the Grid and Range Filter dashboard items. The Chart item displays the filtered data.

The DashboardViewer.ConfigureDataConnection event is handled to specify the Extract Data Source filename. The DashboardViewer.CustomizeDashboardTitle event handler creates the command button that executes the application’s SetMasterFilterMethod procedure.

The SetMasterFilterMethod procedure uses the DashboardViewer.SetMasterFilter method to select the rows in the Grid dashboard item. The DashboardViewer.SetRange method selects the range in the Range Filter dashboard item.

This example also demonstrates how to handle the DashboardViewer.MasterFilterSet and DashboardViewer.MasterFilterCleared events.

dashboard-viewer-apply-master-filtering-example

View Example: How to Set Master Filter in DashboardViewer

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Collections;
using DevExpress.DashboardCommon;
using System.IO;
using DevExpress.DashboardWin;
using System.Linq;
using DevExpress.XtraEditors;

namespace Dashboard_SetMasterFilter {
    public partial class Form1 : XtraForm {
        public Form1() {
            InitializeComponent();
            dashboardViewer1.ConfigureDataConnection += DashboardViewer1_ConfigureDataConnection;
            dashboardViewer1.CustomizeDashboardTitle += DashboardViewer1_CustomizeDashboardTitle;

            dashboardViewer1.LoadDashboard("Dashboard.xml");

            dashboardViewer1.MasterFilterSet += DashboardViewer1_MasterFilterSet;
            dashboardViewer1.MasterFilterCleared += DashboardViewer1_MasterFilterCleared;
        }

        private void SetMasterFilterMethod()
        {
            // Create a list with values to select in the Grid dashboard item.
            List<object> rowValues1 = new List<object>();
            rowValues1.AddRange(new[] { "UK", "Anne Dodsworth" });
            List<object> rowValues2 = new List<object>();
            rowValues2.AddRange(new[] { "USA", "Andrew Fuller" });
            List<IList> selectedRows = new List<IList>(new[] { rowValues1, rowValues2 });

            // Create a selection range and specify its minimum and maximum values.
            DateTime minimumValue = new DateTime(2015, 3, 1);
            DateTime maximumValue = new DateTime(2016, 3, 1);
            RangeFilterSelection selectedRange = new RangeFilterSelection(minimumValue, maximumValue);

            // Select the values in the Grid dashboard item.
            dashboardViewer1.SetMasterFilter("gridDashboardItem1", selectedRows);
            // Select the range in the Range Filter dashboard item.
            dashboardViewer1.SetRange("rangeFilterDashboardItem1", selectedRange);
        }

        private void DashboardViewer1_MasterFilterSet(object sender, MasterFilterSetEventArgs e)
        {
            DashboardViewer viewer = (DashboardViewer)sender;
            // If the Master Filter includes Anne Dodsworth as Sales Person, disable print and export.
            if (e.DashboardItemName.Contains("grid"))
                viewer.AllowPrintDashboard = e.SelectedValues.Select(value => value[1].ToString()).Contains("Anne Dodsworth") ? false : true;
        }

        private void DashboardViewer1_MasterFilterCleared(object sender, MasterFilterClearedEventArgs e)
        {
            MessageBox.Show("Selection cleared in the " + e.DashboardItemName + "Master Filter item.");
        }

        private void DashboardViewer1_CustomizeDashboardTitle(object sender, CustomizeDashboardTitleEventArgs e)
        {
            DashboardViewer viewer = (DashboardViewer)sender;

            // Create the command button to set Master Filter.
            DashboardToolbarItem setMasterFilterItem = new DashboardToolbarItem("Set Master Filter",
                new Action<DashboardToolbarItemClickEventArgs>((args) => { SetMasterFilterMethod(); }));
            setMasterFilterItem.Caption = "Set Master Filter";
            e.Items.Insert(0, setMasterFilterItem);
        }

        private void DashboardViewer1_ConfigureDataConnection(object sender, DashboardConfigureDataConnectionEventArgs e)
        {
            ExtractDataSourceConnectionParameters parameters = e.ConnectionParameters as ExtractDataSourceConnectionParameters;
            if (parameters != null)
                parameters.FileName = Path.GetFileName(parameters.FileName);
        }
    }
}
See Also