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
790
Right click to select a record in extended selection mode, with already few records selected in it
posted

Hi

I would like to select a record upon mouse right click. The data grid is setup for extended selection mode and I'm able to select record on right click if my data grid doesn't have any preselected rows. However, it behaves differently when already one or more records selected in it. Please help me with this issue. Sample code provided below:

xaml

<igDataPresenter:XamDataGrid.Resources>
<Style TargetType="{x:Type igDataPresenter:DataRecordPresenter}">
<EventSetter Event="MouseRightButtonDown" Handler="XamDataGrid_OnMouseRightButtonDown"/>
</Style>
</igDataPresenter:XamDataGrid.Resources>

xaml.cs

private void XamDataGrid_OnMouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
var viewModel = DataContext as StructureViewModel;
if (viewModel != null)
{

var dataRecordPresenter = sender as DataRecordPresenter;
if (dataRecordPresenter != null && dataRecordPresenter.Record != null && dataGrid != null)
{
dataRecordPresenter.Record.IsSelected = true;
}
}
}

Thanks

Parents
  • 34830
    Offline posted

    Hello,

    Thank you for your post.

    I believe what may be happening here is that by using the dataRecordPresenter.Record.IsSelected = true code, you are essentially setting that record to be the only selected record in the XamDataGrid, and you are clearing the XamDataGrid's SelectedItems collection of all records except that one.

    I would recommend that instead of setting the record's IsSelected property, that you use the following code for the selection:

    dataRecordPresenter.DataPresenter.SelectedItems.Records.Add(dataRecordPresenter.Record);

    This will simply add the record to the selected items collection, rather than clearing the collection and setting that record as the only selected one.

    Please let me know if you have any other questions or concerns on this matter.

    Sincerely,
    Andrew
    Developer Support Engineer I
    Infragistics Inc.
    www.infragistics.com/support

Reply Children