Changing the existing context menu of column header in radgridview

4 posts, 0 answers
  1. Sree
    Sree avatar
    30 posts
    Member since:
    Dec 2012

    Posted 02 Jan 2013 Link to this post

    Hello Team,
    I have a requirement in the gridview, in such a way that it should allow me to add additional menu items to the exiting context menu of column header, my gridview contains  columns like Depth, Densities with corresponding Unit of measurements meters (m) and Specific gravity (sg), i should allow user to convert the Unit of measurement of Depth column to feet from meters,
    For this i want to add some menu items to the existing context menu of column header, and then multiply entire column with scaling factor 3.8 so that it converts from meters to feet.

    Can you help me out how to add context menu items to the existing ???
  2. Plamen
    Admin
    Plamen avatar
    132 posts

    Posted 05 Jan 2013 Link to this post

    Hi Lakshmi,

    Thank you for writing.

    The default RadGridView context menu can be customized in the ContextMenuOpening event handler. 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 e.ContextMenu.Items:
    void radGridView1_ContextMenuOpening1(object sender, Telerik.WinControls.UI.ContextMenuOpeningEventArgs e)
    {
        RadMenuItem customMenuItem = new RadMenuItem();
        customMenuItem.Text = "Custom Data Operation";
        RadMenuSeparatorItem separator = new RadMenuSeparatorItem();
        e.ContextMenu.Items.Add(separator);
        e.ContextMenu.Items.Add(customMenuItem);
    }

    More information about the grid's context menu is available here: http://www.telerik.com/help/winforms/gridview-context-menus-modifying-the-default-context-menu.html.

    I hope this helps.

    Kind regards,
    Plamen
    the Telerik team
    Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Sree
    Sree avatar
    30 posts
    Member since:
    Dec 2012

    Posted 07 Jan 2013 Link to this post

    Hello Plamen,

    I have added items to the menu but how to implement the logic on gridview column when right click and selected menuitems from the context menu, for example in the below image i have clicked 'm-ft' menu item from UNIT CONVERSION Menu, in menuitem click event i need to take the current gridview column and multiply the entire column with some factor value to convert from meters to feet


    i was suggested to add radmenuitemmft.Click += new EventHandler(radmenuitemmft_Click);

      void radmenuitemmft.Click(object sender, EventArgs e)
            {            
               
            }
    radmenuitemmft.Click is handling EvenArgs, EventArgs wont able to capture CellFormattingEventArgs of gridview or any, where can i capture the current column index or its name to implement my logic, can you send me an example how the existing gridview handles the context menu


    Thanks
  5. Plamen
    Admin
    Plamen avatar
    132 posts

    Posted 10 Jan 2013 Link to this post

    Hello Lakshmi,

    Thank you for writing.

    For your convenience I have prepared you a sample project. Basically, you can take the ContextMenuProvider from the ContextMenuOpening event which gives you the cell which was right-clicked to invoke the context menu. From the cell you can get the column and then apply customizations to that column only.

    I hope this helps.

    Greetings,
    Plamen
    the Telerik team
    Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
Back to Top