How to disable right click in GridFilterCellElement

3 Answers 62 Views
GridView
Henri
Top achievements
Rank 2
Iron
Iron
Iron
Henri asked on 21 Sep 2023, 11:38 PM

Hi guys,

Anyone knows how to disable the right click in the filter row? As the filter use the same ContextMenuOpening.

 

 

3 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 22 Sep 2023, 01:44 PM

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:

https://www.telerik.com/forums/contextmenuopening-event-doesnt-fire-up-when-right-click-on-the-gridview#2509346 

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.

Henri
Top achievements
Rank 2
Iron
Iron
Iron
commented on 24 Sep 2023, 10:19 PM

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.

0
Henri
Top achievements
Rank 2
Iron
Iron
Iron
answered on 27 Sep 2023, 12:39 AM

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
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 27 Sep 2023, 03:06 PM

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.

Tags
GridView
Asked by
Henri
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Henri
Top achievements
Rank 2
Iron
Iron
Iron
Share this question
or