3 Answers, 1 is accepted
Hello, Henri,
The ContextMenuOpening event is a suitable place to prevent the menu from showing in certain conditions. Considering the ContextMenuProvider and what type of element is applied, you can set the Cancel argument to true. A similiar approach is demonstrated in the following forum thread which I believe will be useful for achieving your custom requirement:
I hope this information helps. If you need any further assistance please don't hesitate to contact me.
Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik
Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.
Hi Dess,
Thanks for your answer, but as I said, it doesn't work as the right click and dropdown for the filter option have the same filter element. My question is, how to disable the right click, but leave the filter options? in e.ContextMenuProvider or in e.ContextMenu they are the same.
Right click in filterrow.
Click in filter options.
To disable the context menu which shows when the user right-clicks on the filtering row and still be able to click on the filtering button. Handling the ContextMenuOpening event is the right place where you can manage when the context menu's pop-up would appear. You can prevent showing the pop-up according to your requirements by setting e.Cancel = true. Here you have access to the GridFilterCellElement and to ContextMenu.Items collection.
Please refer to the following code snippet. The achieved behavior is demonstrated in the attached GIF file.
Private Sub RadGridView1_ContextMenuOpening(ByVal sender As Object, ByVal e As ContextMenuOpeningEventArgs)
Dim filterCell = TryCast(e.ContextMenuProvider, GridFilterCellElement)
If filterCell IsNot Nothing Then
If TypeOf e.ContextMenu.Items.First Is RadFilterOperationMenuItem Then
e.Cancel = False
Else
e.Cancel = True
End If
End If
End Sub
Hello, Henri,
I can confirm that the same event is used when right-clicking the filter row to show the clipboard options and when you left-click the filter button to show the filter operators. The provided solution with checking whether the type of the first menu item is RadFilterOperationMenuItem is OK.
An alternative solution that I can suggest is to prevent the right-clicking for the filter row with the help of a custom GridFilterRowBehavior. I have prepared a sample code snippet for your reference:
Sub New()
InitializeComponent()
Me.RadGridView1.EnableFiltering = True
Dim gridBehavior As BaseGridBehavior = TryCast(RadGridView1.GridBehavior, BaseGridBehavior)
gridBehavior.UnregisterBehavior(GetType(GridViewFilteringRowInfo))
gridBehavior.RegisterBehavior(GetType(GridViewFilteringRowInfo), New CustomGridFilterRowBehavior())
End Sub
Public Class CustomGridFilterRowBehavior
Inherits GridFilterRowBehavior
Protected Overrides Function OnMouseDownRight(e As MouseEventArgs) As Boolean
Return True
End Function
End Class
Both of the solutions are applicable. You can choose which one better fits your scenario.
Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik
Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.