Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1025
How to set the SelectedItem based on right mouse click.
posted

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

Parents
No Data
Reply
  • 8576
    Verified Answer
    Offline posted
    Hi Rod -
     
    I would listen to the PreviewMouseRightButtonDown event and execute the following code.  Note: The GetAncestorFromType is a handy method in our shared assembly that lets you find an ancestor element by type.  Also - the code below assumes that FieldLayout.Settings.SelectionTypeRecord is set to Single (since you only want 1 record selected at a time)
     

    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;

    }

    }

    Joe
Children