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

Change row selection on right-click

3 Answers 1050 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Brad
Top achievements
Rank 1
Brad asked on 02 May 2018, 08:36 PM

I am using a context menu that gets loaded in the "CellLoaded" event for some cells (i.e. I want the context menu in some columns, but not in others).  I have this working beautifully except for one minor problem.  When the user right-clicks the cell, the row selection doesn't change.  So, if I right-click a cell that is not in the active row, the context menu is for a cell that is in an unselected row.  The visual of this is not satisfactory to the client.  "IsSynchronizedWithCurrentItem" works great for left-clicks, but doesn't seem to have any effect for right-clicks.  Is there an easy way to fix this so that if I right-click on a cell, the row selection changes to match?

I've been trying to do this using the grid's "ContextMenuOpening" event, but there doesn't seem to be enough information available in the arguments to tell me which row was clicked on.

Any help would be much-appreciated.

Thanks!

Brad.

3 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 07 May 2018, 01:45 PM
Hi Brad,

In order to select an item on right mouse button click, you can hook up to the MouseRightButtonUp event of the control and set the IsSelected property of the given row to True. The approach is discussed in greater detail in the Select row with right mouse click forum thread. Can you please take a look at it?

Regards,
Stefan
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
1
Brad
Top achievements
Rank 1
answered on 14 May 2018, 04:49 PM

Sorry for my slow reply - I was out of town.

OK, I got it working that way, though I'm not crazy about how it's implemented.  I'm using MVVM and, whereas that thread refers to MVVM, it doesn't actually solve it using MVVM - the MVVM part of the thread dies.  For example, it says use "MouseRightButtonUp instead ItemClick of the menu".  Well, 1) that's for Silverlight, and 2) neither of those is really MVVM unless I can bind a command to them.

 

Thanks!

Brad.

0
Stefan
Telerik team
answered on 16 May 2018, 02:47 PM
Hello Brad,

Thanks for the update.

Indeed, the demo referred in the forum thread is for Silverlight, but the implementation demonstrated in it is applicable for WPF as well. We actually have the same Row Context Menu WPF Demo. Since you are not convenient with the approach of using an attached behavior, you can consider utilizing the EventToCommandBehavior mechanism. Can you please take a look at it?

Regards,
Stefan
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
GridView
Asked by
Brad
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Brad
Top achievements
Rank 1
Share this question
or