GridView ChildTemplate ContextMenu

8 posts, 0 answers
  1. Craig
    Craig avatar
    4 posts
    Member since:
    Apr 2011

    Posted 10 Oct 2013 Link to this post

    How do I get a context menu to show up for a childtemplate in a radgridview?
    Thx.
    Craig
  2. Stefan
    Admin
    Stefan avatar
    2911 posts

    Posted 11 Oct 2013 Link to this post

    Hi Craig,

    By default the context menus are enabled for all templates in RadGridView. You can control whether a context menu will be shown or not via the AllowCellContextMenu property of the desired template.

    I hope this helps.

    Regards,
    Stefan
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. Craig
    Craig avatar
    4 posts
    Member since:
    Apr 2011

    Posted 11 Oct 2013 Link to this post

    Thanks Stefan, but I need my own context menu, not the built in cell menu. How do I override the built in cell menu with my own for a childtemplate 4 levels deep? Sorry if I wasn't clear enough originally.
    Thanks.
    Craig
  4. Stefan
    Admin
    Stefan avatar
    2911 posts

    Posted 15 Oct 2013 Link to this post

    Hello Craig,

    In the ContextMenuOpening event you have the ContextMenuProvider in the event arguments, and from it you can get the GridViewTemplate. Here is an example:
    void radGridView1_ContextMenuOpening(object sender, ContextMenuOpeningEventArgs e)
    {
        GridCellElement cellElement = e.ContextMenuProvider as GridCellElement;
        if (cellElement != null)
        {
            Console.WriteLine(cellElement.ViewTemplate.Caption);
        }
    }

    I hope this helps.

    Regards,
    Stefan
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  5. Craig
    Craig avatar
    4 posts
    Member since:
    Apr 2011

    Posted 15 Oct 2013 Link to this post

    Thanks Stefan that worked perfectly.  But it did make me have another question.  If I need to open a new ticket, please just let me know and I will.  I need to retrieve the value of the a particular cell in my template: gvExcel.MasterTemplate.Templates(0).  I could not find any selectedrows collection for the childtemplate to determine what was the actual selected row in my childtemplate.  I used the ContextMenuOpening event to drill into the cellelement.rowelement.rowinfo.cells to get my field value and save it for use in the menuitem's click event.  Seems like a bad solution to me.  When I'm in the menuitem's click event for this childtemplate, how do I retrieve the currently selected row from that childtemplate?
    Thanks.
    Craig
  6. Stefan
    Admin
    Stefan avatar
    2911 posts

    Posted 16 Oct 2013 Link to this post

    Hi Craig,

    Thank you for writing back.

    The SelectedRows collection is only on the MasterTemplate and it contains all SelectedRows in the grid, no matter in which template.

    If you want to check the rows only in a certain template, you can iterate its Rows collection and check each row IsSelected property:
    void radGridView1_ContextMenuOpening(object sender, ContextMenuOpeningEventArgs e)
    {
        GridCellElement cellElement = e.ContextMenuProvider as GridCellElement;
        if (cellElement != null)
        {
            foreach (GridViewRowInfo row in cellElement.ViewTemplate.Rows)
            {
                if (row.IsSelected)
                {
                    Console.WriteLine("this row is selected");
                }
            }
        }
    }

    I hope this helps.

    About the separate tickets question, in general one should separate the questions that are not related to each other in separate threads.

    Let us know if you have any other questions.

    Regards,
    Stefan
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  7. Craig
    Craig avatar
    4 posts
    Member since:
    Apr 2011

    Posted 16 Oct 2013 Link to this post

    Stefan,
    Thanks, but I didn't ask my question very well.  I am doing exactly what you suggested in the ContextMenuOpening event.  I'm saving my key value from the selected row into a class level variable - almost exactly as you suggested.  Then, when I actually click the RadMenuItemAddSP menu and fire the RadMenuItemAddSP.Click event where I actually need the selected row's value I have it in my saved variable.  That works, but seems kind of like a workaround to me.  What I meant to be asking was once I've selected my contextmenuitem and I'm in the click event of that menu item, how do I traverse the childtemplate grid and retrieve the selected row directly in that function instead of having to save it off in a variable from the ContextMenuOpening event.  I don't see any events to use from e in the click event of the menu item itself. Forgot to mention I have the Grids all set to singleselect mode, so I know there is only one selected row in each level of the grid.
    Typed all this to realize you've already answered my question.  I just need to loop through the SelectedRows of my grid and check the ViewTemplate.Caption property to see if it matches the template I need.  If so, that's my row!  I'll close this ticket.
    Thanks so much for your help.

     

     

     

  8. Stefan
    Admin
    Stefan avatar
    2911 posts

    Posted 17 Oct 2013 Link to this post

    I am glad you this case sorted out.  Let us know if you need anything else.

    Regards,
    Stefan
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top