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

Context menu in the grid header

2 Answers 123 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
ron klod
Top achievements
Rank 1
ron klod asked on 13 Aug 2010, 01:02 PM
Hi,

Ihave a class that inherits from RadGridView,
for each instacne of this grid we always add a button in the header of the first column, when clicking on this button it shold open a context menu, I have locked at your example onhow to do it but it does not work for me, here is my code:
this is the code that I am adding to the grid header, it is being added in OnApplyTemplate:
GridViewColumn column =
this.Columns[0];
           string headerText = column.Header.ToString();
           StackPanel headerPanel = new StackPanel();
           headerPanel.Orientation = Orientation.Horizontal;
           Button b = new Button();
           b.Content = "Menu";
           b.Click += new RoutedEventHandler(b_Click);
           headerPanel.Children.Add(b);
           TextBlock t = new TextBlock();
           t.Text = headerText;
           headerPanel.Children.Add(t);
           column.Header = headerPanel;

this is the event hanlder of the added button
void b_Click(object sender, RoutedEventArgs e)
       {
           RadContextMenu contextMenu = new RadContextMenu();
           contextMenu.ItemClick += new Telerik.Windows.RadRoutedEventHandler(contextMenu_ItemClick);
           // set menu Theme
           StyleManager.SetTheme(contextMenu, StyleManager.GetTheme(this));
           RadMenuItem item = new RadMenuItem() { Header = "Export CSV" };
           //item.Click += new Telerik.Windows.RadRoutedEventHandler(item_Click);
           contextMenu.Items.Add(item);
           RadMenuItem item1 = new RadMenuItem() { Header = "Print" };
           //item1.Click += new Telerik.Windows.RadRoutedEventHandler(item1_Click);
           contextMenu.Items.Add(item1);
           //contextMenu.AddHandler(RadMenuItem.ClickEvent, new RoutedEventHandler(OnMenuItemClick));\\
           RadContextMenu.SetContextMenu((sender as Button), contextMenu);
              
           // attach menu
          // RadContextMenu.SetContextMenu(cell, contextMenu);
     
       }

what am I doing worng? when I click on the button the menu is not opened

Thanks

Ron

2 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 13 Aug 2010, 01:10 PM
Hi ,

 If you want this button to have context menu you should add the menu (and associate this menu with the button) when the button is created - not on click.

Greetings,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
ron klod
Top achievements
Rank 1
answered on 13 Aug 2010, 01:13 PM
Hi,

thanks for the quick response, can you send me an example of how to do it?
Tags
GridView
Asked by
ron klod
Top achievements
Rank 1
Answers by
Vlad
Telerik team
ron klod
Top achievements
Rank 1
Share this question
or