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

GridView ChildTemplate ContextMenu

7 Answers 128 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Craig
Top achievements
Rank 1
Craig asked on 10 Oct 2013, 04:11 PM
How do I get a context menu to show up for a childtemplate in a radgridview?
Thx.
Craig

7 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 11 Oct 2013, 05:54 AM
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 >>
0
Craig
Top achievements
Rank 1
answered on 11 Oct 2013, 10:03 AM
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
0
Stefan
Telerik team
answered on 15 Oct 2013, 02:39 PM
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 >>
0
Craig
Top achievements
Rank 1
answered on 15 Oct 2013, 08:26 PM
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
0
Stefan
Telerik team
answered on 16 Oct 2013, 12:27 PM
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 >>
0
Craig
Top achievements
Rank 1
answered on 16 Oct 2013, 03:18 PM
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.

 

 

 

0
Stefan
Telerik team
answered on 17 Oct 2013, 11:39 AM
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 >>
Tags
GridView
Asked by
Craig
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Craig
Top achievements
Rank 1
Share this question
or