Edit this page

The default RadVirtualGrid context menu can be customized in the ContextMenuOpening event.

Removing an item from the default RadVirtualGrid context menu:


private void Remove_ContextMenuOpening(object sender, VirtualGridContextMenuOpeningEventArgs e)
{
    for (int i = 0; i < e.ContextMenu.Items.Count; i++)
    {
        if (e.ContextMenu.Items[i].Text == "Delete")
        {
            // hide the Delete option from the context menu
            e.ContextMenu.Items[i].Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
            // hide the separator before the Delete option
            e.ContextMenu.Items[i - 1].Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
        }
    }
}

Private Sub Remove_ContextMenuOpening(sender As Object, e As VirtualGridContextMenuOpeningEventArgs)
    For i As Integer = 0 To e.ContextMenu.Items.Count - 1
        If e.ContextMenu.Items(i).Text = "Delete" Then
            ' hide the Delete option from the context menu
            e.ContextMenu.Items(i).Visibility = Telerik.WinControls.ElementVisibility.Collapsed
            ' hide the separator before the Delete option
            e.ContextMenu.Items(i - 1).Visibility = Telerik.WinControls.ElementVisibility.Collapsed
        End If
    Next
End Sub

Default Context Menu Modified Context Menu
virtualgrid-modifying-the-default-context-menu 001 virtualgrid-modifying-the-default-context-menu 002

Adding menu items to the default RadVirtualGrid context menu

In order to add custom menu items to the default context menu, you should create menu item instances in the ContextMenuOpening event handler and add them to the VirtualGridContextMenuOpeningEventArgs.ContextMenu.Items collection:

Adding items to the default RadVirtualGrid context menu:


private void Add_ContextMenuOpening(object sender, VirtualGridContextMenuOpeningEventArgs e)
{
    RadMenuItem customMenuItem = new RadMenuItem();
    customMenuItem.Text = "Custom Data Operation";
    RadMenuSeparatorItem separator = new RadMenuSeparatorItem();
    e.ContextMenu.Items.Add(separator);
    e.ContextMenu.Items.Add(customMenuItem);
}

Private Sub Add_ContextMenuOpening(sender As Object, e As VirtualGridContextMenuOpeningEventArgs)
    Dim customMenuItem As New RadMenuItem()
    customMenuItem.Text = "Custom Data Operation"
    Dim separator As New RadMenuSeparatorItem()
    e.ContextMenu.Items.Add(separator)
    e.ContextMenu.Items.Add(customMenuItem)
End Sub

Default Context Menu Modified Context Menu
virtualgrid-modifying-the-default-context-menu 001 virtualgrid-modifying-the-default-context-menu 003

See Also