Back to Devexpress

DashboardPopupMenuShowingEventArgs Class

dashboard-devexpress-dot-dashboardwin-3f6a6713.md

latest8.3 KB
Original Source

DashboardPopupMenuShowingEventArgs Class

Provides data for the DashboardViewer.PopupMenuShowing, IDashboardControl.PopupMenuShowing, and the DashboardDesigner.PopupMenuShowing events.

Namespace : DevExpress.DashboardWin

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

NuGet Package : DevExpress.Win.Dashboard

Declaration

csharp
public class DashboardPopupMenuShowingEventArgs :
    DashboardItemMouseHitTestEventArgs
vb
Public Class DashboardPopupMenuShowingEventArgs
    Inherits DashboardItemMouseHitTestEventArgs

DashboardPopupMenuShowingEventArgs is the data class for the following events:

Remarks

The PopupMenuShowing event occurs when a user invokes a pop-up menu in the UI. This event allows you to customize the pop-up menu that is invoked when a user right-clicks a dashboard item or clicks a command button in the dashboard title or the dashboard item caption.

Use the following properties in the PopupMenuShowing event handler to customize the pop-up menu:

The e.DashboardArea property identifies the pop-up menu’s location. The e.DashboardItemArea property gets the area of the target dashboard item.

The e.DashboardItemName property obtains the dashboard item name for which the event is raised. To identify the clicked command button, use the e.ButtonType property.

Use the e.Menu property to customize the pop-up menu. You can set the e.Allow property to false or assign null to the e.Menu property to prevent users from invoking the menu.

Example

The following example shows how to customize the Pivot dashboard item’s pop-up menu:

The PopupMenuShowing event occurs each time a user invokes a pop-up menu and adds the “Custom Menu Item” link to the Pivot’s menu. Note that you need to remove the previously added “Custom Menu Item” link from BarItemLinkCollection each time the event fires. Otherwise, the pop-up menu creates “Custom Menu Item” copies.

csharp
using DevExpress.XtraBars;
using System.Data;
using System.Linq;
using System.Windows.Forms;

namespace DashboardSample {
    public partial class Form1 : Form {
        // Creates a new bar item.
        BarButtonItem _newBarItem;
        BarButtonItem NewBarItem {
            get {
                if (_newBarItem == null) {
                    _newBarItem = new BarButtonItem();
                    _newBarItem.Caption = "Custom Menu Item";
                    _newBarItem.ItemClick += NewItem_ItemClick;
                }
                return _newBarItem;
            }
        }
        public Form1() {
            InitializeComponent();
            dashboardDesigner1.CreateRibbon();
            dashboardDesigner1.LoadDashboard("DataFolder/nwind.xml");
        }
        private void dashboardDesigner1_PopupMenuShowing(object sender, DevExpress.DashboardWin.DashboardPopupMenuShowingEventArgs e) {
            BarItemLink existingItemLink = e.Menu.ItemLinks.Where(link => link.Item == _newBarItem).FirstOrDefault();
            if (e.DashboardItemName == "pivotDashboardItem1") {
                // Inserts the item link in the Pivot's pop-up menu.
                if (existingItemLink != null)
                    e.Menu.ItemLinks.Remove(existingItemLink);
                    e.Menu.ItemLinks.Insert(0, NewBarItem);
            }
            else {
                // Removes the added link for other dashboard items.
                e.Menu.ItemLinks.Remove(existingItemLink);
            }
        }
        // Shows a message when a user clicks the Custom Menu Item in the invoked pop-up menu.
        private void NewItem_ItemClick(object sender, ItemClickEventArgs e) {
            MessageBox.Show("Custom Menu Item Clicked");
        }
    }
}
vb
Imports DevExpress.XtraBars
Imports System.Data
Imports System.Linq
Imports System.Windows.Forms

Namespace DesignerSample
    Partial Public Class Form1
        Inherits Form
        ' Creates a new bar item.
        Private _newBarItem As BarButtonItem
        Private ReadOnly Property NewBarItem() As BarButtonItem
            Get
                If _newBarItem Is Nothing Then
                    _newBarItem = New BarButtonItem()
                    _newBarItem.Caption = "Custom Menu Item"
                    AddHandler _newBarItem.ItemClick, AddressOf NewItem_ItemClick
                End If
                Return _newBarItem
            End Get
        End Property
        Public Sub New()
            InitializeComponent()
            dashboardDesigner1.CreateRibbon()
            dashboardDesigner1.LoadDashboard("DataFolder/nwind.xml")
        End Sub
        Private Sub dashboardDesigner1_PopupMenuShowing(ByVal sender As Object, ByVal e As DevExpress.DashboardWin.DashboardPopupMenuShowingEventArgs)
            Dim existingItemLink As BarItemLink = e.Menu.ItemLinks.Where(Function(link) link.Item Is _newBarItem).FirstOrDefault()
            If e.DashboardItemName = "pivotDashboardItem1" Then
                ' Inserts the item link in the Pivot's pop-up menu.
                If existingItemLink IsNot Nothing Then
                    e.Menu.ItemLinks.Remove(existingItemLink)
                End If
                    e.Menu.ItemLinks.Insert(0, NewBarItem)
            Else
                ' Removes the added link for other dashboard items.
                e.Menu.ItemLinks.Remove(existingItemLink)
            End If
        End Sub
        ' Shows a message when a user clicks the Custom Menu Item in the invoked pop-up menu.
        Private Sub NewItem_ItemClick(ByVal sender As Object, ByVal e As ItemClickEventArgs)
            MessageBox.Show("Custom Menu Item Clicked")
        End Sub
    End Class
End Namespace

Inheritance

Object EventArgs DashboardItemMouseEventArgs DashboardItemMouseHitTestEventArgs DashboardPopupMenuShowingEventArgs

See Also

DashboardPopupMenuShowingEventArgs Members

DashboardViewer.PopupMenuShowing

IDashboardControl.PopupMenuShowing

DashboardDesigner.PopupMenuShowing

DevExpress.DashboardWin Namespace