Using Shift-Click to Select Multiple DataGrid Rows

After looking at the demo I see that I can select a row, and then Control-Click to select other rows. However, if I select the top row and then Shift-Click the bottom row, I don't see the same behavior. I would expect all the rows in between to be selected on a Shift-Click.

Is it possible to enable that functionality?

1 Like

No, such selection mode is not currently supported.

Ok, thank you for the quick response. Are there any plans to support that selection mode in the future?

Hi, is there a way or example of how we could implement this? This would be a time saving feature for me. Grtz Thomas

Are there any plans to implement this functionality?
Or an example of how this can be done

An example implementation might look like this

private T? _startRow;
private T? _endRow;
private RadzenDataGridColumn<T>? _startColumn;
private RadzenDataGridColumn<T>? _endColumn;

void Select(DataGridCellMouseEventArgs<T> args)
{
	_startRow = args.Data;
	_startColumn = args.Column;

	if (args.ShiftKey)
	{
		SelectRange(args);
	}
	else
	{
		if (!args.CtrlKey)
			_selectedCellData.Clear();

		var cellData = _selectedCellData.FirstOrDefault(i => i.Item1 == args.Data && i.Item2 == args.Column);
		if (cellData != null)
			_selectedCellData.Remove(cellData);
		else
			_selectedCellData.Add(new Tuple<T, RadzenDataGridColumn<T>>(args.Data, args.Column));

		_endRow = args.Data;
		_endColumn = args.Column;
		_startRow = null;
		_startColumn = null;
	}
}

void SelectRange(DataGridCellMouseEventArgs<T> args)
{
	if (_startRow == null || _endRow == null || _startColumn == null || _endColumn == null)
		return;

	var dataList = Data.ToList();
	var startIndex = dataList.IndexOf(_startRow);
	var endIndex = dataList.IndexOf(_endRow);

	if (startIndex == -1 || endIndex == -1)
		return;

	if (startIndex > endIndex)
		(startIndex, endIndex) = (endIndex, startIndex);

	var columnsList = _dataGrid.ColumnsCollection.ToList();
	var startColumnIndex = columnsList.IndexOf(_startColumn);
	var endColumnIndex = columnsList.IndexOf(_endColumn);

	if (startColumnIndex == -1 || endColumnIndex == -1)
		return;

	if (startColumnIndex > endColumnIndex)
		(startColumnIndex, endColumnIndex) = (endColumnIndex, startColumnIndex);

	for (var i = startIndex; i <= endIndex; i++)
		for (var j = startColumnIndex; j <= endColumnIndex; j++)
		{
			var rowData = schedulesList[i];
			var columnData = columnsList[j];
			var cellData = new Tuple<T, RadzenDataGridColumn<T>>(rowData, columnData);
			if (!_selectedCellData.Contains(cellData))
				_selectedCellData.Add(cellData);
		}

	_endRow = _startRow;
	_startRow = null;
	_endColumn = _startColumn;
	_startColumn = null;
}

This is cool but couldn't implement it.

Can we have a full source code or project?

Can you submit a PR for this? would be useful for me too

I dont create PR for this feature