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

RadGrid w/ RadContextMenu

3 Answers 155 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Zeke Sheppard
Top achievements
Rank 1
Zeke Sheppard asked on 22 Sep 2010, 07:59 PM
Greetings:

For a RadGrid with the following settings;

 

<ClientSettings EnablePostBackOnRowClick="true">

 

 

<Selecting AllowRowSelect="True" />

 

 

</ClientSettings>

 


And a RadContextMenu is configured as shown;

<

 

telerik:RadContextMenu ID="rcmContextMenu" iscontext="True" runat="server" Skin="Outlook"

 

 

OnItemClick="rcmContextMenu_ItemClick" contextmenuelementid="none">

 

 

<Items>

 

 

<telerik:RadMenuItem Text="Edit" />

 

 

 

<telerik:RadMenuItem Text="Delete" />
</

 

Items>

 

</

 

telerik:RadContextMenu>

 



The following occurs when a RadContextMenu is used on the RadGrid;

1) Right click on selected grid row.
2) Context menu appears as expected
3) An item is selected off of the context menu
4) RadGrid_SelectedIndexChanged event is fired
5) RadContextMenu_ItemClick event is fired

How is it possible to use a RadContextMenu when RadGrid_SelectedIndexChanged fires when an item is selected off of the context menu before RadContextMenu_ItemClick fires?


3 Answers, 1 is accepted

Sort by
0
Marin
Telerik team
answered on 27 Sep 2010, 03:37 PM
Hi Zeke Sheppard,

The RadGrid_SelectedIndexChanged fires before the RadContextMenu_ItemClick because you probably select it programatically in the client event hadler for RadContextMenu_ItemClick like this

sender.get_masterTableView().selectItem(sender.get_masterTableView())

If this is the case please try removing this row and see if the event fires as correctly.

All the best,
Marin
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Zeke Sheppard
Top achievements
Rank 1
answered on 27 Sep 2010, 03:45 PM

A value is required from the grid row when the context menu item is selected. This is accomplished by the following:
CType

 

(Page, WISH_Default).GenericString = rgvIntentDetail.Items(hdnGridClickedRowIndex.Value).Item("SID_CUST_GRADE").Text

But this is in the following event handler:

 

 

Protected Sub rcmContextMenu_ItemClick(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadMenuEventArgs)

 


This would not appear to cause the RadGrid selected index changed event to fire first, since the grid is referenced in the event handler for the context menu.

Once again, how is it possible to prevent

 

Private Sub RadGrid_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles rgvIntentDetail.SelectedIndexChanged

from firing when an item is selected from the context menu?

 

0
Marin
Telerik team
answered on 29 Sep 2010, 05:27 AM
Hi Zeke Sheppard,

As you can see how it is in this demo. If you wire the RadGrid_SelectedIndexChanged event it will also fire before the RadMenu1_ItemClick event. If I understood you correctly this is not the desired behavior. You can fix it in the following way:
In the client javascript code in the .aspx file there should be an event handler like the following 

function RowContextMenu(sender, eventArgs)
{
var menu = $find("<%=RadMenu1.ClientID %>");
var evt = eventArgs.get_domEvent();
if(evt.target.tagName == "INPUT" || evt.target.tagName == "A")
{
return;
}
var index = eventArgs.get_itemIndexHierarchical();
document.getElementById("radGridClickedRowIndex").value = index;
sender.get_masterTableView().selectItem(sender.get_masterTableView().get_dataItems()[index].get_element(), true);
menu.show(evt);
evt.cancelBubble = true;
evt.returnValue = false;
if (evt.stopPropagation)
{
evt.stopPropagation();
evt.preventDefault();
}
}

The marked line is manually selecting the item which causes the SelectedIndexChanged event to fire first.
If you remove this line

sender.get_masterTableView().selectItem(sender.get_masterTableView().get_dataItems()[index].get_element(),
true);

the problem should be resolved.

Regards,

Marin
the Telerik team

 

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Zeke Sheppard
Top achievements
Rank 1
Answers by
Marin
Telerik team
Zeke Sheppard
Top achievements
Rank 1
Share this question
or