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) 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;
}
}