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
1170
Treat shift/ctrl click cell selection as record selection
posted

I have a grid where all the columns are editable, and users frequently need to select a subset of rows. I've got the record selector column visible, but they'd also like to select rows by holding shift or ctrl and clicking on a cell in a given row. For now I've set SelectionTypeCell to None to try and avoid confusion, but at least with this default style if you select a few rows, then hold shift and click an adjacent row, it looks a lot like the adjacent record is now selected as well, when in fact there's no change to the SelectedItems collections.

Is there a way to select a record on shift or ctrl click of a single cell, without removing the basic behavior of clicking a cell to enter edit mode?

Barring that, can I modify the style of this grid so that the non-selected records I described above have a different row background?

Parents
  • 34510
    Verified Answer
    Offline posted

    Hi John,

    The row looks like it's selected because the active row has the same background as a selected row.  When you click on a cell it makes the row the ActiveRecord but it does not select the row.  The simplest way to change this would be to set the FieldSettings.CellClickAction to "SelectRecord".  If you don't want to do this though you'll need to manually select the record yourself which means detecting what cell was clicked on and selecting it's row.  Something like this: 

    private void XamDataGrid_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        if (Keyboard.IsKeyDown(Key.LeftCtrl))
        {
            // find out which cell was clicked on.
            Point mousePos = e.GetPosition(sender as XamDataGrid);
            HitTestResult result = VisualTreeHelper.HitTest(sender as Visual, mousePos);
            if (result != null)
            {
                CellValuePresenter cvp = (CellValuePresenter)Infragistics.Windows.Utilities.GetAncestorFromType(result.VisualHit, typeof(CellValuePresenter), true);
                if (cvp != null)
                    cvp.Record.IsSelected = true;
            }
        }
    }

     

    You can change the background of active rows by creating a DataRecordCellArea style and setting the BackgroundActive property. 

    <Style TargetType="{x:Type igDP:DataRecordCellArea}">
        <Setter Property="BackgroundActive" Value="{StaticResource MyActiveRowBackground}"/>
    </Style>

     

Reply Children
No Data