This is a migrated thread and some comments may be shown as answers.

Disable default ContextMenu in RadGrid

10 Answers 1377 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Technik
Top achievements
Rank 1
Technik asked on 06 May 2008, 10:02 AM
Hi,

I am unable to disable the context menu of the radgrid. I built my own Menu and set the Property

        Me.RadGridView1.ContextMenuStrip = MyOwnContextMenu

Now it shows both, my own menu and the default menu (copy, sort ascending, etc). How can I hide / disable the default ?


Using :
    RadControls for WinForms Q1/2008
    VB.Net

Greetings

10 Answers, 1 is accepted

Sort by
0
Justin White
Top achievements
Rank 1
answered on 06 May 2008, 02:07 PM

Hi Falk,

Try subscribing to the ContectMenuOpeningEventHandler event on your grid:

 myGrid.ContextMenuOpening += new ContextMenuOpeningEventHandler(myGrid_ContextMenuOpening); 

And then in that event:
void _rgvVehicleHistory_ContextMenuOpening(object sender, ContextMenuOpeningEventArgs e)  
{  
    e.Cancel = true; // This hides all context menus completely  
 
   // OR  
 
   e.ContextMenu = myContextMenu; // To show your context menu  

Hope that helps!

Justin
2
Martin Vasilev
Telerik team
answered on 06 May 2008, 02:21 PM
Hello Falk Wegener,

Thank you for writing.

You could disable the default context menu in RadGridView by using the code provided below:
Me.radGridView1.MasterGridViewTemplate.AllowColumnHeaderContextMenu = False 
Me.radGridView1.MasterGridViewTemplate.AllowCellContextMenu = False 

I hope this helps. If you have additional questions, do not hesitate to contact me again.

Regards,
Martin Vasilev
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Raviraj
Top achievements
Rank 1
commented on 29 Nov 2021, 02:38 AM

This is exact case I have been looking for. It did wonders.
Dess | Tech Support Engineer, Principal
Telerik team
commented on 29 Nov 2021, 05:20 AM

HI, Raviraj, If you want to disable the default context menu in RadGridView, feel free to cancel the ContextMenuOpening event: 
        private void RadGridView1_ContextMenuOpening(object sender, 
            Telerik.WinControls.UI.ContextMenuOpeningEventArgs e)
        {
            e.Cancel = true;
        }
0
Technik
Top achievements
Rank 1
answered on 06 May 2008, 02:21 PM
Thanks, that works , sort of.

During the initialization of my Form I set the ContextMenuStrip

RadGridView1.ContextMenuStrip = MyContextMenu  

Then I subscribed to the event as you said.

Private Sub RadGridView1_ContextMenuOpening(ByVal sender As ObjectByVal e As Telerik.WinControls.UI.ContextMenuOpeningEventArgs) Handles RadGridView1.ContextMenuOpening 
  e.Cancel = True 
End Sub 

This actually cancels only the default contextmenu. MyContextMenu is still shown, so this is what I want. Still a bit strange, there seem to be two different ContextMenus.


Thanks for your help!
0
Bruce Lam
Top achievements
Rank 1
answered on 14 Sep 2009, 12:26 PM
How can i just show delete in ContextMenu. and another is disable. Please help me as impossible as.Thanks alot
0
Martin Vasilev
Telerik team
answered on 16 Sep 2009, 12:37 PM
Hello Iam,

Thank you for the question. You can access the ContextMenu in ContextMenuOpenning event handler and customize it according to your needs. For example if you want to leave only Delete Row item in the DataCell context menu you can use the following code:

void radGridView1_ContextMenuOpening(object sender, ContextMenuOpeningEventArgs e) 
    GridDataCellElement cell = e.ContextMenuProvider as GridDataCellElement; 
 
    if (cell != null
    { 
        RadItem deleteItem = e.ContextMenu.Items[4]; 
        e.ContextMenu.Items.Clear(); 
 
        e.ContextMenu.Items.Add(deleteItem); 
    } 

I hope this helps. Write me back if you need additional assistance.

All the best,
Martin Vasilev
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Bruce Lam
Top achievements
Rank 1
answered on 17 Sep 2009, 06:14 AM
Thanks you alot
0
NORIS
Top achievements
Rank 1
answered on 23 Sep 2009, 05:16 PM
Hello Martin,
I do not have the Delete Row item in the DataCell context menu.  I have the grid set to allow delete rows.
Why do I not have this item and how do I get  it?
If code is provided please use VB.
Thanks.

 Also, forgot to add that I can not select multipe rows.  I have selectionmode as fullrowselect and multiselect as true, but using Ctrl or Shift does not allow me to select more than one row.  I would like to delete all selected rows.
I am using the DataSource as a SQL data table, if that matters.
Thanks again.
0
Jack
Telerik team
answered on 25 Sep 2009, 07:32 AM
Hi NORIS,

As I can see, you are using an old version of RadControls for WinForms. You should not experience these issues with our latest release - Q2 2009 SP1. I recommend that you try out this version. It contains many improvements and addresses a lot of issues. I will be glad to help you with the transition process.

If you continue experiencing the issue, please send me your project and I will try to locate it. I am looking forward to your reply.

Kind regards,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
NORIS
Top achievements
Rank 1
answered on 25 Sep 2009, 12:32 PM
Sorry, but I am using Q2 2009 SP1.  It's the only version I've used.
Am I missing something?
0
Jack
Telerik team
answered on 26 Sep 2009, 06:18 AM
Hello NORIS,

That's strange. Please send me your application and I will try to find out what is wrong. I am looking forward to your response.

Greetings,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
Technik
Top achievements
Rank 1
Answers by
Justin White
Top achievements
Rank 1
Martin Vasilev
Telerik team
Technik
Top achievements
Rank 1
Bruce Lam
Top achievements
Rank 1
NORIS
Top achievements
Rank 1
Jack
Telerik team
Share this question
or