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

Changing the existing context menu of column header in radgridview

3 Answers 579 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sree
Top achievements
Rank 1
Sree asked on 03 Jan 2013, 01:51 AM
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 ???

3 Answers, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 05 Jan 2013, 08:09 AM
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.
0
Sree
Top achievements
Rank 1
answered on 08 Jan 2013, 04:16 AM
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
0
Plamen
Telerik team
answered on 10 Jan 2013, 04:59 PM
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.
Tags
GridView
Asked by
Sree
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Sree
Top achievements
Rank 1
Share this question
or