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?
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>
Thanks, this will probably work, although I did notice one thing... If you set cvp.Record.IsSelected = true, you're assuming the record was not selected, and is not being deselected. I'd suggest for anyone else looking at this to make it cvp.Record.IsSelected = !cvp.Record.IsSelected.
The other thing I did was implement a style with triggers that set the active row background based on Record.IsSelected, so that the rows appearance accurately reflects the state I'm interested in. Thanks for putting me on the right track.