windowsforms-devexpress-dot-utils-dot-menu-dot-dxmenuitem-3ceff441.md
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
public object Tag { get; set; }
Public Property Tag As Object
| Type | Description |
|---|---|
| Object |
An object that contains the information which is associated with the menu item.
|
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.
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:
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);
}
}
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
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
toggleTotalItem.BeginGroup = true;
toggleTotalItem.Tag = e.Field;
e.Menu.Items.Add(toggleTotalItem);
menuItem.Image = GetMdiTabPageImage(page);
menuItem.Tag = page.MdiChild;
winforms-pivot-change-summarydisplaytype-in-context-menu/CS/WindowsApplication34/Form1.cs#L45
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
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
toggleTotalItem.BeginGroup = True
toggleTotalItem.Tag = e.Field
e.Menu.Items.Add(toggleTotalItem)
winforms-pivot-change-summarydisplaytype-in-context-menu/VB/WindowsApplication34/Form1.vb#L48
AddHandler item.Click, AddressOf ItemClick
item.Tag = e.Field
sdtItem.Items.Add(item)
menuItem.Image = GetMdiTabPageImage(page)
menuItem.Tag = page.MdiChild
Return menuItem
See Also