Remove the default right click menu in cell edit

2 posts, 0 answers
  1. jaya
    jaya avatar
    4 posts
    Member since:
    Sep 2018

    Posted 18 Oct 2018 Link to this post

    How to remove the default right click menu in cell edit? Attached image for your reference.
    I need to add the Radcontext menu in the grid’s cell edit option.
  2. Dimitar
    Admin
    Dimitar avatar
    2839 posts

    Posted 19 Oct 2018 Link to this post

    Hi Jaya,

    You can use the CellEditorInitialized event to access the editor and change the default context menu. Here is a complete example of this:
    RadContextMenu myMenu = new RadContextMenu();
    public RadForm1()
    {
        InitializeComponent();
        for (int i = 0; i < 5; i++)
        {
            myMenu.Items.Add(new RadMenuItem("Item" + i));
        }
        radGridView1.DataSource = GetTable();
        radGridView1.CellEditorInitialized += RadGridView1_CellEditorInitialized;
    }
     
    private void RadGridView1_CellEditorInitialized(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
    {
        var editor = e.ActiveEditor as RadTextBoxEditor;
        if (editor != null)
        {
            var element = editor.EditorElement as RadTextBoxEditorElement;
            element.TextBoxItem.HostedControl.ContextMenu = new ContextMenu();
            element.TextBoxItem.HostedControl.MouseDown -= TextBoxItem_MouseDown;
            element.TextBoxItem.HostedControl.MouseDown += TextBoxItem_MouseDown;
        }
    }
     
    private void TextBoxItem_MouseDown(object sender, MouseEventArgs e)
    {
        var textbox = sender as Control;
        myMenu.Show(textbox, e.Location);
    }

    I hope this will be useful. Let me know if you have additional questions.

    Regards,
    Dimitar
    Progress Telerik
    Get quickly onboard and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top