
Richard Harrigan
Top achievements
Rank 1
Richard Harrigan
asked on 21 Jul 2010, 04:34 AM
Hi,
In a grid with three levels I am trying to use context menus. I have created MouseRightButtonDown/Up events for all three levels. The problem I am having is that when the event fires for a child row the event also fires for each parent level. What I think I need to do is have just one event for the entire grid and discover based on position what object I am in when clicked. How can I do this?
Thanks
Rich
In a grid with three levels I am trying to use context menus. I have created MouseRightButtonDown/Up events for all three levels. The problem I am having is that when the event fires for a child row the event also fires for each parent level. What I think I need to do is have just one event for the entire grid and discover based on position what object I am in when clicked. How can I do this?
Thanks
Rich
5 Answers, 1 is accepted
0
Hi Richard Harrigan,
I am sending you a sample project that you can use as a reference.
Maya
the Telerik team
You can add different ContextMenus for every grid during the RowLoaded event instead. For example:
private void playersGrid_RowLoaded(object sender, RowLoadedEventArgs e)
{
if (!(e.Row is GridViewHeaderRow) && !(e.Row is GridViewNewRow))
{
RadContextMenu rowContextMenu = new RadContextMenu(); // create menu
// create menu items
rowContextMenu.Items.Add(new RadMenuItem() { Header = "Item2.1"});
rowContextMenu.Items.Add(new RadMenuItem() { Header = "Item2.2"});
RadContextMenu.SetContextMenu(e.Row, rowContextMenu);
}
}
I am sending you a sample project that you can use as a reference.
Maya
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

Richard Harrigan
Top achievements
Rank 1
answered on 22 Jul 2010, 12:52 AM
Thanks that worked good (I put in in the xaml). Now that it worked my next question is how do I get the instance of the data in the row that I pressed the right mouse. Basically what I want to do at the point is CRUD operations. I want the Edit Context Menu to cause a data form to be displayed for data the row clicked on. In the case of the New Context menu I want to also create an empty data form.
Should I be creating a new thread? It seem easier to just continue with the same thread but I want to do the correct thing.
Thanks
Rich
Should I be creating a new thread? It seem easier to just continue with the same thread but I want to do the correct thing.
Thanks
Rich
0
Hello Richard Harrigan,
Where Country, Name and Number are Properties of object of type Player.
However, a possible approach for editing an item would be to use RowDetails. You can find detailed information about this scenario in this blog post.
Regards,
Maya
the Telerik team
Firstly, you can use the ItemClick event of the RadContextMenu. Furthermore, you can get the values in the cells of the selected row using the Properties of the item inside. For example:
Player selectedPlayer = this.playersGrid.SelectedItem as Player;
string country = selectedPlayer.Country;
string name = selectedPlayer.Name;
int number = selectedPlayer.Number;
Where Country, Name and Number are Properties of object of type Player.
However, a possible approach for editing an item would be to use RowDetails. You can find detailed information about this scenario in this blog post.
Regards,
Maya
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

Richard Harrigan
Top achievements
Rank 1
answered on 23 Jul 2010, 06:10 PM
Hi Maya,
The ItemClick event does does not provide a SelectedItem when the ItemClick is fired by a RightMouse Click. I don't want the user to have to select the row before pressing the RightMouse. I think we need a function or something so we can return the GridRow based on the RightMouse clicks X, Y position. Even if I require the row item to be selected first the user could always then RightMouse Click on another row which would cause me to edit the wrong row. Also, I don't think using comman buttons instead of contextmenu for CRUD is a good option on a multi-level grid.
Thanks
Rich
The ItemClick event does does not provide a SelectedItem when the ItemClick is fired by a RightMouse Click. I don't want the user to have to select the row before pressing the RightMouse. I think we need a function or something so we can return the GridRow based on the RightMouse clicks X, Y position. Even if I require the row item to be selected first the user could always then RightMouse Click on another row which would cause me to edit the wrong row. Also, I don't think using comman buttons instead of contextmenu for CRUD is a good option on a multi-level grid.
Thanks
Rich
0
Hi Richard Harrigan,
void rowContextMenu_Opened(object sender, RoutedEventArgs e)
{
}
Thus the "clickedRow" would be exactly the row you need.
Sincerely yours,
Maya
the Telerik team
A good approach for your scenario would be to listen for the Opened event of RadContextMenu and to use the GetClickedElement method in order to get the row you are right-clicking on. For example:
private void clubsGrid_RowLoaded(object sender, Telerik.Windows.Controls.GridView.RowLoadedEventArgs e)
{if (!(e.Row is GridViewHeaderRow) && !(e.Row is GridViewNewRow))
{
RadContextMenu rowContextMenu = new RadContextMenu(); // create menu
rowContextMenu.Opened += new RoutedEventHandler(rowContextMenu_Opened);
rowContextMenu.Items.Add(new RadMenuItem() { Header = "ParentGrid" });
rowContextMenu.Items.Add(new RadMenuItem() { Header = "Item1.1" });
rowContextMenu.Items.Add(new RadMenuItem() { Header = "Item1.2" });
RadContextMenu.SetContextMenu(e.Row, rowContextMenu);
}
}
void rowContextMenu_Opened(object sender, RoutedEventArgs e)
{
RadContextMenu menu = sender as RadContextMenu;
var clickedRow = menu.GetClickedElement<GridViewRow>();
}
Thus the "clickedRow" would be exactly the row you need.
Sincerely yours,
Maya
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