Hi All,
I am fighting with XAmDataGRid to implement the record selections with pressed shift key. User should be able to select records when he PRess Shift key and click on another row. Could u please help me ASAP.
Note :- I need CellClickAction = SelectCell, and I dont want to use the left most record selector arrow.
Thanks
Hi anant_9sept,
The XamDataGrid only allows selection of cells or records but not at the same time. If you set the CellClickAction to SelectCell, every time you click on a cell it is going to clear the selected records and since the selection mode is set on the cell rather than the row, holding down the Shift key while clicking on cells will select all of those cells. It won't select the row itself. In order to select records the CellClickAction needs to be SelectRecord so that rows may be selectable. You can then press the Shift key or the Ctrl key to select multiple records.
Dude this is possble to implement Multi Select rows with "CellClickAction=SelectCell"....
I made is yesterday itself.... Let me share with you all.....
XAML:-
<igDP:XamDataGrid Name="_grid"PreviewKeyDown="OnGridKey" KeyDown="OnGridKey" KeyUp="OnGridKey" PreviewKeyUp="OnGridKey"/>
Note:- i attched all the key up and key down so that we dont loose shift boolean to be not set incorrectly.
Code Behind:-
private void OnGridSelectedItemsChanged(object sender, SelectedItemsChangedEventArgs args) { if (!_shiftPressed && _grid.SelectedItems.Cells.Count > 0) _selectedCell = _grid.SelectedItems.Cells[0].Record.Index; if (_shiftPressed && _grid.SelectedItems.Cells.Count > 0) _shiftSelectedCell = _grid.SelectedItems.Cells[0].Record.Index; if (_selectedCell > -1 && _shiftSelectedCell > -1 && _shiftPressed) { _shiftPressed = false; _grid.SelectedItems.Records.Clear(); IList<Record> list = new List<Record>(); for (int i = Math.Min(_selectedCell, _shiftSelectedCell); i <= Math.Max(_selectedCell, _shiftSelectedCell); i++) { list.Add(_grid.Records[i]); } _selectedCell = -1; _shiftSelectedCell = -1; _grid.SelectedItems.Records.AddRange(list.ToArray()); }
}
private bool _shiftPressed; private int _selectedCell; private int _shiftSelectedCell; private void OnGridKey(object sender, System.Windows.Input.KeyEventArgs e) { if ((e.Key == System.Windows.Input.Key.LeftShift || e.Key == System.Windows.Input.Key.RightShift) && e.IsDown) { _shiftPressed = true; } else { _shiftPressed = false; } }