Articles in this section

How to add different context menu for each cells?

To load different ContextMenu items for different cells, the CellContextMenuOpening event can be customized. In that event, the CellContextMenu property can be used to assign the custom menu items.

 

C#

//Event subsciption
grid.CellContextMenuOpening += CellGrid_CellContextMenuOpening;
 
//Event customization
private void CellGrid_CellContextMenuOpening(object sender, CellContextMenuOpeningEventArgs e)
{
    if (e.Cell.ColumnIndex == 0 && e.Cell.RowIndex > 0) 
        e.CellContextMenu = GetRowCellMenu(); //Gets context menu items for rows.
    else if (e.Cell.RowIndex == 0 && e.Cell.ColumnIndex > 0)
        e.CellContextMenu = GetColumnCellMenu();// Gets context menu items for columns
    else
        e.CellContextMenu = GetCellContextMenu(); //// Gets context menu items for Cells
}
 
private ContextMenu GetCellContextMenu()
{
    ContextMenu contextMenu = new ContextMenu();
    for (int i = 0; i < 5; i++)
    {
        MenuFlyoutItem query = new MenuFlyoutItem { Text = string.Format("Cell{0}", i), Height = 50, VerticalAlignment = VerticalAlignment.Center };
        contextMenu.Items?.Add(query);
    }
    return contextMenu;
}

 

screenshot that demonstrates CellContextMenu

 

Download GridDemo from GitHub

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied