I have a context menu set up on the xamDataGrid. When I right click I would like the Records that I right clicked on to be the one and only SelectedItem.
Thanks,
Rod
void xamDataGrid1_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
DependencyObject source = e.OriginalSource as DependencyObject; if (source == null) return; DataRecordPresenter drp = Infragistics.Windows.Utilities.GetAncestorFromType(source, typeof(DataRecordPresenter), true) as DataRecordPresenter; if (drp == null) return; if (drp.Record != null) { drp.Record.IsSelected = true; drp.IsActive = tru; }
DependencyObject source = e.OriginalSource as DependencyObject;
if (source == null)
return;
DataRecordPresenter drp = Infragistics.Windows.Utilities.GetAncestorFromType(source, typeof(DataRecordPresenter), true) as DataRecordPresenter;
if (drp == null)
if (drp.Record != null)
{ drp.Record.IsSelected = true; drp.IsActive = tru; }
drp.Record.IsSelected = true; drp.IsActive = tru;
drp.Record.IsSelected = true;
drp.IsActive = tru;
}
Do you have any good suggestions on how to make this support multiple-record selection. I was trying to capture key events to try and track the user holding down CTRL/SHIFT to determine if the selected records should be cleared on the mouse click but the key events don't seem to be triggered. I also tried the preview key events.
Thanks!
-Tammy
Too easy. I was just using the wrong method to determine if the keys were pressed.
Seems simple to me. CAn you try to Keep a collection of SelectedItems, assume at start is has no items. On PreviewMouseRightButtonDown check if CTRL key is pressed Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)
if Ctrl key is not pressed clear the collection. Always add the new item to the collection.
That way, if ctrl is pressed you will keep on adding items to the collection. You done have to listen to Key press events.