Articles in this section
Category / Section

How to enable Custom Context Menu in GridDataControl

1 min read

ContextMenu displays a list of menu items added to it and performs the specified action when you click on the menu items. In GridDataControl, you can enable the ContextMenu by setting EnableContextMenu property as ‘True’. The ContextMenu for Headers, Records and GroupCaption area are enabled with default MenuItems. You can customize these context menu items using theContextMenuOptions” property.

ContextMenuOptions

GridDataControl contain the following ContextMenu options.

Default

Using Default options we can enable the default context menu items only.

Custom

Using Custom context menu options we can create the context menu items based on our requirement.

CustomWithDefault

Using CustomWithDefault option we can add context menu items to the default context menu items.

 

ContextMenuItems

You can customize the HeaderContextMenuItems, GroupHeaderContextMenuItems and RecordContextMenuItems by adding the new menu items to the collection.

For example, you can create menu items for records like “Add”, ”Remove”,” Update” as shown in the following code sample.

XAML

<syncfusion:GridDataControl x:Name="grid"                                         
                            AllowGroup="True"
                            EnableContextMenu="True"                                                           
                            ContextMenuOptions="CustomWithDefault"
                            AutoPopulateColumns="False"
                            AutoPopulateRelations="False"
                            ItemsSource="{Binding GDCSource}"
                            ShowAddNewRow="False"
                            ShowGroupDropArea="True">

 

C#

this.grid.HeaderContextMenuItems = GetHeaderContextMenu();
this.grid.GroupHeaderContextMenuItems = GetGroupHeaderContextMenu();
this.grid.RecordContextMenuItems = GetRecordContextMenu();
 
public List<MenuItem> GetHeaderContextMenu()
{
    List<MenuItem> list = new List<MenuItem>();
    list.Add(new MenuItem() { Header = " Header Context Menu 1" });
    list.Add(new MenuItem() { Header = " Header Context Menu 2" });
    list.Add(new MenuItem() { Header = " Header Context Menu 3" });
    return list; 
}
public List<MenuItem> GetGroupHeaderContextMenu()
{
    List<MenuItem> list = new List<MenuItem>();
    list.Add(new MenuItem() { Header = " Group Header Context Menu 1" });
    list.Add(new MenuItem() { Header = " Group Header Context Menu 2" });
    list.Add(new MenuItem() { Header = " Group Header Context Menu 3" });
    return list; 
}
public List<MenuItem> GetRecordContextMenu()
{
    List<MenuItem> list = new List<MenuItem>();
    list.Add(new MenuItem() { Header = "Add" });
    list.Add(new MenuItem() { Header = "Remove" });
    list.Add(new MenuItem() { Header = "Update" });
    return list; 
}






 

The following screenshot illustrates the output for customizing the ContextMenu based on cell value using the QueryContextMenuInfo event in GridDataControl.

 

D:\Syncfusion\Issues\2014 Volume 2\KB Issues\KB Images\Customization based on cell value.png

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