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

separate context menu for grid headers

1 Answer 135 Views
This is a migrated thread and some comments may be shown as answers.
ofer alper
Top achievements
Rank 1
ofer alper asked on 20 Jan 2010, 10:38 AM

I need separate context menu for the grid rows and the grid headers.

I defined the rows context menu in the xaml like this:

<telerikGrid:RadGridView x:Name="ordersGrid" AutoGenerateColumns="False" DataLoadMode="Synchronous" >
                <Navigation:RadContextMenu Opened="RadContextMenu_Opened" ItemClick="RadContextMenu_ItemClick">
                        <Navigation:RadMenuItem Header="Update Order" />
                        <Navigation:RadMenuItem Header="Cancel Order" />
                        <Navigation:RadMenuItem Header="View Details" />

and i defined in the code the context menu for the headers.

The problem is that the main context menu overrides the header context menu. I even try to remove it in the loaded event but it didn't help:

        void ordersGrid_Loaded(object sender, RoutedEventArgs e)
            GridViewHeaderRow headerRow = ordersGrid.ChildrenOfType<GridViewHeaderRow>().FirstOrDefault();
            IEnumerable<GridViewHeaderCell> cells = headerRow.Cells.OfType<GridViewHeaderCell>();

            /**remove the default menu from the header in order to ser a separate menu for header**/
            foreach (GridViewHeaderCell cell in cells)
                var x = cell.ContextMenu;
                RadContextMenu.SetContextMenu(cell, null);
            GridViewHeaderMenu gvhm = new GridViewHeaderMenu(ordersGrid);

How can i achieve it?



1 Answer, 1 is accepted

Sort by
Pavel Pavlov
Telerik team
answered on 22 Jan 2010, 05:38 PM
Hi ofer alper,

Instead of setting  context menu for the entire RadGridView I would reccomend to do the following :

Using global style set the context menu to GridViewHeaderCell( as target type)   and the same way another context menu to the GridViewCell element.

Let me know if you have any troubles implementing this approach.

Sincerely yours,
Pavel Pavlov
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.
Asked by
ofer alper
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Share this question