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

[Solved] GroupHeaderItem Context Menu

3 Answers 156 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 2
Jason asked on 27 Apr 2009, 02:24 PM
Hi,

I've got a RadTreeView that drives a RadGrids datasource on each node click.  I can right click a row on my RadGrid and get a context menu etc...  This all works fine.  What I can't do is get the context menu to display when I right click a group header item in my RadGrid.

I've also noticed that when my app first loads my context menu will display when right clicking on the RadGrids header bar and on the "No records to display message".   When the app starts there are never any records to display in the RagGrid.

However after I click on a RadTreeView node which in turn calls a rebind (successfully, the Grid now has records and group header items) the context menu will no longer work on the header bar or any future "No records" messages,  but will work fine on any row item.

Hope you can help?

Thanks
Jase

P.S.  My productivity has gone through the roof ever since I switched to Teleriks RadControls.  Great stuff !!

3 Answers, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 30 Apr 2009, 12:34 PM
Hi Jason,

I am not aware of the details of your implementation and cannot say for certain what the problem might be. However, in general, if you want to add context menu to the group header item and no-records-template item, then you can try the following:

1. Attach an event handler to the grid's item created event and add the code below:

    protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)  
    {  
        if (e.Item is GridGroupHeaderItem)  
        {  
            e.Item.Attributes.Add("oncontextmenu""return GroupHeaderMenu();");  
        }  
        else if (e.Item is GridNoRecordsItem)  
        {  
            e.Item.Attributes.Add("oncontextmenu""return GroupHeaderMenu();");  
        }  
    } 

2. Add the client event handler:

    <telerik:RadScriptBlock runat="server" ID="RadScriptBlock1">  
 
        <script type="text/javascript">  
 
           function GroupHeaderMenu()  
           {  
           
                var evt = window.event;  
                  
                     
                var menu = $find("<%=RadMenu1.ClientID %>");  
                      
                menu.show(evt);  
                     
                evt.cancelBubble = true;  
                evt.returnValue = false;  
                  
                if (evt.stopPropagation)  
                {  
                    evt.stopPropagation();  
                    evt.preventDefault();  
                }  
           }  
             
             
        </script>  
 
    </telerik:RadScriptBlock> 

I hope this information helps.

Greetings,
Tsvetoslav
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
Jason
Top achievements
Rank 2
answered on 30 Apr 2009, 02:02 PM
Tsvetoslav,

Thats great thanks, it works well.  I'm so pleased that I dropped a compitetors tool set and picked up yours.  I'm really getting results with Teleriks RadControls.

I've tweaked this to show different context menus for the GridGroupHeaderItem, GridNoRecordsItem and GridDataItem.

When I right click the GridDataItem and show the context menu I can get the dataitem selected in the grid.  Can I do the same for the GridGroupHeaderItem and get it to expand?

Thanks
Jase
0
Sebastian
Telerik team
answered on 04 May 2009, 10:56 AM
Hi Jason,

Thank you for the nice words about our controls.

Unfortunately the GridGroupHeaderItem is not directly accessible on the client. To expand it you may consider using approach similar to the one presented in this code library thread (see the last project attached in it).

Best regards,
Sebastian
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.
Tags
Grid
Asked by
Jason
Top achievements
Rank 2
Answers by
Tsvetoslav
Telerik team
Jason
Top achievements
Rank 2
Sebastian
Telerik team
Share this question
or