Back to Devexpress

DashboardViewer.MasterFilterDefaultValues Event

dashboard-devexpress-dot-dashboardwin-dot-dashboardviewer-441a7a86.md

latest10.3 KB
Original Source

DashboardViewer.MasterFilterDefaultValues Event

Allows you to apply default filtering to master filter items.

Namespace : DevExpress.DashboardWin

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

NuGet Package : DevExpress.Win.Dashboard

Declaration

csharp
public event MasterFilterDefaultValuesEventHandler MasterFilterDefaultValues
vb
Public Event MasterFilterDefaultValues As MasterFilterDefaultValuesEventHandler

Event Data

The MasterFilterDefaultValues event's data class is MasterFilterDefaultValuesEventArgs. The following properties provide information specific to this event:

PropertyDescription
AvailableFilterValuesGets the list of values that can be used to apply filtering.
FilterValuesGets or sets values used to apply default filtering.
ItemComponentNameGets the component name of the dashboard item.
ItemNameGets the dashboard item name.

The event data class exposes the following methods:

MethodDescription
GetFilterValues()Gets the collection of values that can be used to apply default filtering.
SetFilterValues(IEnumerable<IList>)Specifies values used to apply default filtering.

Remarks

All master filter items (except the RangeFilterDashboardItem) raise the MasterFilterDefaultValues event when the Dashboard control (designer or viewer) loads a dashboard. The RangeFilterDashboardItem raises the RangeFilterDefaultValue event.

Handle this event to reduce the application load time and decrease memory consumption, because the event occurs before the data is loaded.

Follow the steps below to write the correct MasterFilterDefaultValues event handler.

  1. Check the dashboard item’s name. Use the MasterFilterDefaultValuesEventArgs.ItemName or MasterFilterDefaultValuesEventArgs.ItemComponentName properties.
  2. Select required filter values from the available filter values. Use the MasterFilterDefaultValuesEventArgs.AvailableFilterValues property.
  3. Apply the master filter. For this, assign selected filter values to the MasterFilterDefaultValuesEventArgs.FilterValues property or call the MasterFilterDefaultValuesEventArgs.SetFilterValues method.

Important

This event is not raised in asynchronous mode. Use the SetInitialDashboardState event to set the default filter values. See Manage Dashboard State for more information about a dashboard state.

Example

This example demonstrates how to initialize master filter in a dashboard loaded in the DashboardViewer control. The code for the DashboardDesigner control is the same, because the DashboardDesigner’s events have the same name and functionality.

The following code initializes master filter items:

Master filter initialization can apply one item’s master filter to another master filter item - a mutual filtering occurs. In that scenario, the MasterFilterDefaultValues event has limitations if the Neutral Filter mode is disabled.

csharp
using DevExpress.DashboardCommon;
using System;
using System.Linq;

namespace Dashboard_MFDefaultValues
{
    public partial class Form1 : DevExpress.XtraEditors.XtraForm {
        public Form1() {
            InitializeComponent();
            dashboardViewer1.UseNeutralFilterMode = true;
            dashboardViewer1.ConfigureDataConnection += DashboardViewer1_ConfigureDataConnection;
            dashboardViewer1.MasterFilterDefaultValues += DashboardViewer1_MasterFilterDefaultValues;
            dashboardViewer1.RangeFilterDefaultValue += DashboardViewer1_RangeFilterDefaultValue;

            dashboardViewer1.Dashboard = new Dashboard1();
        }

        private void DashboardViewer1_ConfigureDataConnection(object sender, DashboardConfigureDataConnectionEventArgs e)
        {
            ExtractDataSourceConnectionParameters connParameters = e.ConnectionParameters as ExtractDataSourceConnectionParameters;
            connParameters.FileName = "Data\\SalesPerson.dat";
        }

        private void DashboardViewer1_MasterFilterDefaultValues(object sender, MasterFilterDefaultValuesEventArgs e) {
            if (e.ItemComponentName == "gridDashboardItem1") {
                e.FilterValues = e.AvailableFilterValues.Where(v => (string)v["Sales Person"] == "Laura Callahan");
            }
            if (e.ItemComponentName == "treeViewDashboardItem1") {
                e.FilterValues = e.AvailableFilterValues.Where(v => (string)v["Category"] == "Beverages" || 
                    (string)v["Product"] == "Aniseed Syrup");
            }
        }

        private void DashboardViewer1_RangeFilterDefaultValue(object sender, RangeFilterDefaultValueEventArgs e) {
            if (e.DashboardItemName == "rangeFilterDashboardItem1") {
                e.Range = new RangeFilterSelection(new DateTime(2015, 06, 01), new DateTime(2016, 04, 01));
            }
        }
    }
}
vb
Imports DevExpress.DashboardCommon
Imports System
Imports System.Linq

Namespace Dashboard_MFDefaultValues

    Public Partial Class Form1
        Inherits DevExpress.XtraEditors.XtraForm

        Public Sub New()
            InitializeComponent()
            dashboardViewer1.UseNeutralFilterMode = True
            AddHandler dashboardViewer1.ConfigureDataConnection, AddressOf DashboardViewer1_ConfigureDataConnection
            AddHandler dashboardViewer1.MasterFilterDefaultValues, AddressOf DashboardViewer1_MasterFilterDefaultValues
            AddHandler dashboardViewer1.RangeFilterDefaultValue, AddressOf DashboardViewer1_RangeFilterDefaultValue
            dashboardViewer1.Dashboard = New Dashboard1()
        End Sub

        Private Sub DashboardViewer1_ConfigureDataConnection(ByVal sender As Object, ByVal e As DashboardConfigureDataConnectionEventArgs)
            Dim connParameters As ExtractDataSourceConnectionParameters = TryCast(e.ConnectionParameters, ExtractDataSourceConnectionParameters)
            connParameters.FileName = "Data\SalesPerson.dat"
        End Sub

        Private Sub DashboardViewer1_MasterFilterDefaultValues(ByVal sender As Object, ByVal e As MasterFilterDefaultValuesEventArgs)
            If Equals(e.ItemComponentName, "gridDashboardItem1") Then
                e.FilterValues = e.AvailableFilterValues.Where(Function(v) Equals(CStr(v("Sales Person")), "Laura Callahan"))
            End If

            If Equals(e.ItemComponentName, "treeViewDashboardItem1") Then
                e.FilterValues = e.AvailableFilterValues.Where(Function(v) Equals(CStr(v("Category")), "Beverages") OrElse Equals(CStr(v("Product")), "Aniseed Syrup"))
            End If
        End Sub

        Private Sub DashboardViewer1_RangeFilterDefaultValue(ByVal sender As Object, ByVal e As RangeFilterDefaultValueEventArgs)
            If Equals(e.DashboardItemName, "rangeFilterDashboardItem1") Then
                e.Range = New RangeFilterSelection(New DateTime(2015, 06, 01), New DateTime(2016, 04, 01))
            End If
        End Sub
    End Class
End Namespace

Implements

MasterFilterDefaultValues

See Also

Neutral Filter Mode

RangeFilterDefaultValue

DashboardViewer Class

DashboardViewer Members

DevExpress.DashboardWin Namespace