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

Right Click Context Menu/Select on GridView

1 Answer 539 Views
GridView
This is a migrated thread and some comments may be shown as answers.
heavywoody
Top achievements
Rank 1
heavywoody asked on 11 May 2014, 12:03 AM
 I am running into a selection issue with WPF GridView.   I need the Grid to work just like Windows Explorer as far as using a Context Menu on right click.  Meaning if the user right clicks an item or range of items, the context menu will open and those items will be selected.  What is throwing me if that if I try to put in code to right click/select, I can't get the other items like multiple select using CTRL or SHIFT to work correctly.  So just like Windows Explorer, the rules on selecting would be:

1) User can right click and select an item without left clicking to select first.
2) User can hold down SHIFT and select a range of items then right click/context menu on selected items.
3) User can hold down CTRL and select individual items then right click/context menu on those selected items.

This is what I have tried but it doesn't work if I am using CTRL, selecting items, then right clicking to get Context Menu.  So do you have any suggestions or samples to make it work EXACTLY like Windows Exploring for selecting items?

 private void GroupGrid_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {

            var s = e.OriginalSource as FrameworkElement;
            var parentRow = s.ParentOfType<GridViewRow>();
            var rowItem = parentRow as GridViewRowItem;
            var mediaItem = rowItem as RadRowItem;
            if (gridAdvancedSearch.SelectedItems.Count > 1 && gridAdvancedSearch.SelectedItems.Contains(mediaItem.Item))
            {
                e.Handled = true;
            }
            else
            {
                gridAdvancedSearch.SelectedItems.Clear();

                if (parentRow != null)
                    parentRow.IsSelected = true;
            }

        }

1 Answer, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 12 May 2014, 07:50 AM
Hello,

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

You can also check the "Row Context Menu" WPF Demo.

How does this work for you?

Regards,
Didie
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
GridView
Asked by
heavywoody
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Share this question
or