Right Click Selection and Modifier Keys

4 posts, 1 answers
  1. Corey
    Corey avatar
    26 posts
    Member since:
    Nov 2012

    Posted 28 Mar 2014 Link to this post

    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.
  2. Answer
    Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 02 Apr 2014 Link to this post

    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.

     
  3. DevCraft banner
  4. Corey
    Corey avatar
    26 posts
    Member since:
    Nov 2012

    Posted 04 Apr 2014 in reply to Dimitrina Link to this post

    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.
  5. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 07 Apr 2014 Link to this post

    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.

     
Back to Top