Context menu in GridView

9 posts, 1 answers
  1. Marco
    Marco avatar
    23 posts
    Member since:
    Apr 2009

    Posted 26 May 2009 Link to this post

    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


  2. Answer
    Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 27 May 2009 Link to this post

    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.
  3. DevCraft banner
  4. Marco
    Marco avatar
    23 posts
    Member since:
    Apr 2009

    Posted 28 May 2009 Link to this post

    Thank you for your prompt and accurate response! :)

  5. rb
    rb avatar
    7 posts
    Member since:
    May 2009

    Posted 03 Jun 2009 Link to this post

    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
  6. rb
    rb avatar
    7 posts
    Member since:
    May 2009

    Posted 03 Jun 2009 Link to this post

    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
  7. rb
    rb avatar
    7 posts
    Member since:
    May 2009

    Posted 03 Jun 2009 Link to this post

    I just figured out...I have to add the control dynamically when binding asynchronously to data.

    thanks
    ramu
  8. Paolo
    Paolo avatar
    423 posts
    Member since:
    Jun 2009

    Posted 30 Jun 2009 Link to this post

    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
  9. Sarkis Matossian
    Sarkis Matossian avatar
    8 posts
    Member since:
    Aug 2009

    Posted 10 Feb 2010 Link to this post

    Could someone elaborate on how to add a context menu when loading data asynchronously?

    Thank you.
  10. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 11 Feb 2010 Link to this post

    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.
Back to Top
DevCraft banner