alexa
Syncfusion
menu Syncfusion

MAUI

  • User Guide
  • Demos
  • Support
  • Forums
  • Download
Search Results for

    Show / Hide Table of Contents

    Class ContextMenuOpeningEventArgs

    Provides data for the context menu opening event.

    Inheritance
    object
    EventArgs
    ContextMenuOpeningEventArgs
    Inherited Members
    EventArgs.Empty
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Syncfusion.Maui.DataGrid
    Assembly: Syncfusion.Maui.DataGrid.dll
    Syntax
    public class ContextMenuOpeningEventArgs : EventArgs
    Examples

    Here is an example of how to use the ContextMenuOpeningEventArgs class in the ContextMenuOpening event.

    [XAML]

    <syncfusion:SfDataGrid x:Name="dataGrid"
                            ItemsSource="{Binding YourData}"
                            AutoGenerateColumns="True"
                            ContextMenuOpening="DataGrid_ContextMenuOpening" />

    [C#]

    private void DataGrid_ContextMenuOpening(object sender, ContextMenuOpeningEventArgs e)
    {
        // Add a custom menu item
        e.MenuItems.Add(new MenuItem { Text = "Refresh", Command = ViewModel.RefreshCommand });
    
        // Cancel the menu if needed
        if (e.Column.MappingName == "Status")
        {
            e.Cancel = true;
        }
    }

    Constructors

    ContextMenuOpeningEventArgs()

    Initializes a new instance of the ContextMenuOpeningEventArgs class.

    Declaration
    public ContextMenuOpeningEventArgs()

    Properties

    Cancel

    Gets or sets a value indicating whether the context menu should be canceled and not displayed.

    Declaration
    public bool Cancel { get; set; }
    Property Value
    Type
    bool

    Column

    Gets or sets the column associated with the context menu.

    Declaration
    public DataGridColumn Column { get; set; }
    Property Value
    Type
    DataGridColumn

    MenuItems

    Gets or sets the collection of menu items to display in the context menu.

    Declaration
    public ObservableCollection<MenuItem> MenuItems { get; set; }
    Property Value
    Type
    ObservableCollection<MenuItem>
    Remarks

    The collection is now mutable (ObservableCollection) and supports dynamic updates. Changes to menu item visibility or collection membership are reflected immediately in the UI.

    RowData

    Gets the row data object for data rows, or null for header/summary rows.

    Declaration
    public object? RowData { get; set; }
    Property Value
    Type Description
    object

    The row data for data rows, or null for header rows, group caption rows, group summary rows, or table summary rows.

    Remarks

    This property enables developers to access the row object and make visibility decisions based on row data, such as status, permissions, or other business properties.

    Examples

    Here is an example of how to use the RowData property.

    [C#]

    private void DataGrid_ContextMenuOpening(object sender, ContextMenuOpeningEventArgs e)
    {
        var order = e.RowData as Order;
        if (order != null)
        {
            e.MenuItems.FirstOrDefault(m => m.Text == "Edit")!.IsVisible = order.CanEdit;
            e.MenuItems.FirstOrDefault(m => m.Text == "Delete")!.IsVisible = order.CanDelete;
        }
    }

    RowIndex

    Gets the zero-based row index of the row where the context menu was triggered.

    Declaration
    public int RowIndex { get; set; }
    Property Value
    Type Description
    int

    The zero-based row index.

    Remarks

    This property enables developers to apply row-position-based logic, such as hiding items on even/odd rows or applying patterns based on row number.

    Examples

    Here is an example of how to use the RowIndex property.

    [C#]

    private void DataGrid_ContextMenuOpening(object sender, ContextMenuOpeningEventArgs e)
    {
        // Show items only on even rows (0, 2, 4, ...)
        bool isEvenRow = e.RowIndex % 2 == 0;
        e.MenuItems.FirstOrDefault(m => m.Text == "Edit")!.IsVisible = isEvenRow;
    }

    RowType

    Gets the type of the row where the context menu was triggered.

    Declaration
    public RowType RowType { get; set; }
    Property Value
    Type Description
    RowType

    The RowType value (HeaderRow, DataRow, GroupCaptionRow, GroupSummaryRow, TableSummaryRow).

    Remarks

    This property enables developers to apply row-type-specific logic within a single event handler, such as showing different menu items for header rows vs. data rows.

    Examples

    Here is an example of how to use the RowType property.

    [C#]

    private void DataGrid_ContextMenuOpening(object sender, ContextMenuOpeningEventArgs e)
    {
        if (e.RowType == RowType.HeaderRow)
        {
            // Show column operations (sort, filter, etc.)
            e.MenuItems.FirstOrDefault(m => m.Text == "Sort")!.IsVisible = true;
        }
        else if (e.RowType == RowType.DataRow)
        {
            // Show row operations (edit, delete, etc.)
            e.MenuItems.FirstOrDefault(m => m.Text == "Edit")!.IsVisible = true;
        }
    }
    In this article
    Back to top Generated by DocFX
    Copyright © 2001 - 2026 Syncfusion Inc. All Rights Reserved