Back to Devexpress

DXMenuItem.Tag Property

windowsforms-devexpress-dot-utils-dot-menu-dot-dxmenuitem-3ceff441.md

latest6.8 KB
Original Source

DXMenuItem.Tag Property

Gets or sets the data associated with the menu item.

Namespace : DevExpress.Utils.Menu

Assembly : DevExpress.Utils.v25.2.dll

NuGet Packages : DevExpress.Utils, DevExpress.Wpf.Core

Declaration

csharp
public object Tag { get; set; }
vb
Public Property Tag As Object

Property Value

TypeDescription
Object

An object that contains the information which is associated with the menu item.

|

Remarks

You can use the Tag property to associate any data with a menu item and then use this data for instance in a DXMenuItem.Click event handler.

Example

The following code sample creates a menu item that fixes the column to the left. This item is added to the column header’s context menu next to the Hide This Column item:

csharp
void gridView1_PopupMenuShowing(object sender, PopupMenuShowingEventArgs e) {
    if (e.MenuType == GridMenuType.Column) {
        DXMenuItem item = new DXMenuItem("Fix/Unfix This Column", (s, args) => {
            GridColumn column = (s as DXMenuItem).Tag as GridColumn;
            if (column.Fixed == FixedStyle.Left)
                column.Fixed = FixedStyle.None;
            else column.Fixed = FixedStyle.Left;
        });
        item.Tag = e.HitInfo.Column;
        int index = e.Menu.Items.IndexOf(e.Menu.Find(GridStringId.MenuColumnRemoveColumn));
        e.Menu.Items.Insert(index + 1, item);
    }
}
vb
Private Sub gridView1_PopupMenuShowing(ByVal sender As Object, ByVal e As PopupMenuShowingEventArgs)
    If e.MenuType = GridMenuType.Column Then
        Dim item As DXMenuItem = New DXMenuItem("Fix/Unfix This Column", Function(s, args)
            Dim column As GridColumn = TryCast((TryCast(s, DXMenuItem)).Tag, GridColumn)

            If column.Fixed = FixedStyle.Left Then
                column.Fixed = FixedStyle.None
            Else
                column.Fixed = FixedStyle.Left
            End If
        End Function)
        item.Tag = e.HitInfo.Column
        Dim index As Integer = e.Menu.Items.IndexOf(e.Menu.Find(GridStringId.MenuColumnRemoveColumn))
        e.Menu.Items.Insert(index + 1, item)
    End If
End Sub

The following code snippets (auto-collected from DevExpress Examples) contain references to the Tag property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-grid-customize-footer-menu-calculate-custom-totals/CS/Form1.cs#L54

csharp
DevExpress.Utils.Menu.DXMenuItem menuItem = new DevExpress.Utils.Menu.DXMenuCheckItem("Active Count", check, null, new EventHandler(MyMenuItem));
menuItem.Tag = e.HitInfo.Column;
foreach (DevExpress.Utils.Menu.DXMenuItem item in footerMenu.Items)

winforms-pivot-totals-visibility/CS/Form1.cs#L41

csharp
toggleTotalItem.BeginGroup = true;
toggleTotalItem.Tag = e.Field;
e.Menu.Items.Add(toggleTotalItem);

winforms-tabbed-mdi-manager-display-custom-header-button/CS/WindowsFormsApplication32/MyTabbedMdiManager/MyTabbedMdiManager.cs#L54

csharp
menuItem.Image = GetMdiTabPageImage(page);
menuItem.Tag = page.MdiChild;

winforms-pivot-change-summarydisplaytype-in-context-menu/CS/WindowsApplication34/Form1.cs#L45

csharp
item.Click += new EventHandler(ItemClick);
item.Tag = e.Field;
sdtItem.Items.Add(item);

winforms-grid-customize-footer-menu-calculate-custom-totals/VB/Form1.vb#L47

vb
Dim menuItem As DevExpress.Utils.Menu.DXMenuItem = New DevExpress.Utils.Menu.DXMenuCheckItem("Active Count", check, Nothing, New EventHandler(AddressOf MyMenuItem))
menuItem.Tag = e.HitInfo.Column
For Each item As DevExpress.Utils.Menu.DXMenuItem In footerMenu.Items

winforms-pivot-totals-visibility/VB/Form1.vb#L45

vb
toggleTotalItem.BeginGroup = True
toggleTotalItem.Tag = e.Field
e.Menu.Items.Add(toggleTotalItem)

winforms-pivot-change-summarydisplaytype-in-context-menu/VB/WindowsApplication34/Form1.vb#L48

vb
AddHandler item.Click, AddressOf ItemClick
item.Tag = e.Field
sdtItem.Items.Add(item)

winforms-tabbed-mdi-manager-display-custom-header-button/VB/WindowsFormsApplication32/MyTabbedMdiManager/MyTabbedMdiManager.vb#L46

vb
menuItem.Image = GetMdiTabPageImage(page)
menuItem.Tag = page.MdiChild
Return menuItem

See Also

DXMenuItem Class

DXMenuItem Members

DevExpress.Utils.Menu Namespace