A workaround (not a solution) for improving two of the remaining issues:
For
private void SelectItemsInRectangle(Rect selectionRect, DataGrid dataGrid, object sender, MouseEventArgs e)
you should use the version which was posted here as "Solution 2".
The only problem seems to me when dragging the mouse form start point at bottom of the grid and the (mouse) endpoint on top is on a column header.
The rectangle then ends on the col header and the selection misses the invisible rows from the bottom.
A workaround which improves this, would be disable dataGrid.SelectedItems.Clear()
private void SelectItemsInRectangle(Rect selectionRect, DataGrid dataGrid, object sender, MouseEventArgs e)
{
Another issue is case a cell is selected or in edit mode.
Then the rows selection can be uncomplete.
Here is my workaround:
private void DataGrid_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
var selectionStart = e.GetPosition(FileDataGrid);
if (isSelecting == false)
{
if (FileDataGrid.SelectedCells.Count > 0)
{
var curCell = FileDataGrid.CurrentCell;
FileDataGrid.UnselectAllCells();
if (curCell != null)
{ FileDataGrid.CurrentCell = curCell; }
}
}
selectionStartPoint = selectionStart;
isleftbuttonpressed = true;
isSelecting = true;
adorner = new SelectionAdorner(FileDataGrid, selectionStartPoint);
var adornerLayer = AdornerLayer.GetAdornerLayer(FileDataGrid);
adornerLayer.Add(adorner);
adorner.SetStartPoint(selectionStartPoint);
}
open issue:
When you press left mouse button and drag the mouse while using the mouse wheel for scrolling, the rows selection fails.
Perhaps disable mouse wheel while selecting?
Window size too small, I use:
Title="MainWindow"
Width="935"
Height="650"