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

Context menu in GridView

8 Answers 167 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Marco
Top achievements
Rank 1
Marco asked on 26 May 2009, 10:21 PM
Hi,
I want to use context menus in my grid, but I might be doing something wrong because I only get the Silverlight configuration option when I right click on the grid.

I followed the website example attaching one context menu per row, but the event "OnMenuOpen" never gets triggered

private void SamplesGrid_RowLoaded(object sender, RowLoadedEventArgs e) 
        { 
            if (!(e.Row is GridViewHeaderRow) && !(e.Row is GridViewNewRow)) 
            { 
                var rowContextMenu = new RadContextMenu(); 
                StyleManager.SetTheme(rowContextMenu, StyleManager.GetTheme(SamplesGrid)); 
                rowContextMenu.Items.Add(new RadMenuItem { Header = "Add Row" }); 
                rowContextMenu.Items.Add(new RadMenuItem { Header = "Delete Selected Row(s)" }); 
                rowContextMenu.AddHandler(RadMenuItem.ClickEvent, new RoutedEventHandler(OnMenuItemClick)); 
                rowContextMenu.Opened += OnMenuOpened; 
                RadContextMenu.SetContextMenu(e.Row, rowContextMenu); 
                MessageBox.Show("SamplesGrid_RowLoaded"); 
            } 
        } 
 
        private static void OnMenuOpened(object sender, RoutedEventArgs e) 
        { 
            MessageBox.Show("OnMenuOpened"); 
            var row = ((RadRoutedEventArgs)e).OriginalSource as GridViewRow; 
            if (row != null) 
                row.IsSelected = row.IsCurrent = ((GridViewCell)row.Cells[0]).IsCurrent = true
        } 

Thanks much for your help,
Marco


8 Answers, 1 is accepted

Sort by
0
Accepted
Vlad
Telerik team
answered on 27 May 2009, 05:14 AM
Hi Marco,

You need to set windowless to true for the SL control - please check this thread for more info:
http://silverlight.net/forums/t/94311.aspx

Kind regards,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Marco
Top achievements
Rank 1
answered on 28 May 2009, 03:54 PM
Thank you for your prompt and accurate response! :)

0
rb
Top achievements
Rank 1
answered on 03 Jun 2009, 04:55 PM
Hi,

I added a context menu to the header row by following exactly what you have in the Examples project. For some reason, it just shows Silverlight config. option. I even set WindowLess = true.

Please Help.
thanks
ramu
0
rb
Top achievements
Rank 1
answered on 03 Jun 2009, 04:56 PM
Just to add to my comment above, I am calling a web service and binding the data asynchronously, not sure if this has any impact on ContextMenu
0
rb
Top achievements
Rank 1
answered on 03 Jun 2009, 05:02 PM
I just figured out...I have to add the control dynamically when binding asynchronously to data.

thanks
ramu
0
Michele
Top achievements
Rank 2
answered on 30 Jun 2009, 12:54 PM
I'm exacly facing the same error you had.... can you please tell me the event I need to intercept to add the context menu?
Right now I'm on RowLoaded ...
Thanks in advance

Paolo
0
Sarkis Matossian
Top achievements
Rank 1
answered on 10 Feb 2010, 03:21 PM
Could someone elaborate on how to add a context menu when loading data asynchronously?

Thank you.
0
Vlad
Telerik team
answered on 11 Feb 2010, 06:39 AM
Hi,

You can add the menu for the entire grid statically and show/hide or change menu items conditionally. Please check this demo for more info:
http://demos.telerik.com/silverlight/#GridView/RowContextMenu

Sincerely yours,
Vlad
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
Tags
GridView
Asked by
Marco
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Marco
Top achievements
Rank 1
rb
Top achievements
Rank 1
Michele
Top achievements
Rank 2
Sarkis Matossian
Top achievements
Rank 1
Share this question
or