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

Right Click Selection and Modifier Keys

3 Answers 61 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Corey
Top achievements
Rank 2
Corey asked on 28 Mar 2014, 09:30 PM
I have a simple RadGridView (selection mode is Extended) that has its own RadContextMenu.  Currently, left clicking selects rows while also taking into consideration modifier keys (i.e. holding Control will allow for multiple independent selections, as well as individual deselection).  Right clicking will open a context menu.

What I would like to have is that right clicking would function almost identically to left clicking, while still opening the context menu.  So far, I have modified the RadContextMenu.Opened event handler to select the row that was right clicked (and I even have it intelligent enough to deselect the other rows if the newly clicked row wasn't previously selected).

What I still need is a way to incorporate Shift and Control into the mix, but I haven't seen any way to identify that these keys are being pressed at the same time as the click.  The only thing I can come up with is subscribing the grid to a key press handler that flags global boolean variables that I can check inside of the Opened event handler.  I'd rather not do this, since this might also require special logic for selecting rows when Shift is held.  A simple solution would be much appreciated.

3 Answers, 1 is accepted

Sort by
0
Accepted
Dimitrina
Telerik team
answered on 02 Apr 2014, 02:18 PM
Hello,

Generally you can check what is the modifier key pressed through the Keyboard.Modifiers.
The code would be similar to:
var controlPressed = Keyboard.Modifiers == ModifierKeys.Control; 

You can get this information when the RadContextMenu.Opened event is raised.

Regards,
Didie
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Corey
Top achievements
Rank 2
answered on 04 Apr 2014, 10:07 PM
Thanks for the reply.  Your solution works for the Control key, but in order to make the Shift key work as desired, I would have to find the row index of the last clicked row and select all rows between that one and the newly clicked one.  All in all, I don't believe that specific feature is worth my time, so I will skip out on including the Shift key functionality for now.

Thanks again for the reply though.
0
Dimitrina
Telerik team
answered on 07 Apr 2014, 08:35 AM
Hello,

Once you have the clicked item (row) and a reference of the GridView, you could get the index of the item though the RadGridView.Items.IndexOf(object value) method. 

Regards,
Didie
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
GridView
Asked by
Corey
Top achievements
Rank 2
Answers by
Dimitrina
Telerik team
Corey
Top achievements
Rank 2
Share this question
or