telerik / UI-For-UWP

This repo contains the source code for Telerik UI for Universal Windows Platform (UWP), which includes 20+ UI controls for developers building UWP applications.
http://www.telerik.com/uwp/
Other
1.16k stars 234 forks source link

RadDataGrid -- Extended SelectionMode with Shift+Left Click has limited item selection #455

Open ryanthtra opened 4 years ago

ryanthtra commented 4 years ago

Description

When attempting to select a large number (e.g. >50) of rows on a RadDataGrid with SelectionMode=Extended using Shift+Left Click, only a significant smaller number of rows are actually selected. This can be shown visually as well as programatically (i.e., SelectedItems).

Steps to Reproduce

  1. Click the top 1 or 2 rows of the RadDataGrid.
  2. Scroll to the bottom of the RadDataGrid.
  3. Shift+Left Click the bottom row of the RadDataGrid.

Expected Behavior

All rows are selected.

Actual Behavior

A much smaller number of rows are selected.

Basic Information

Screenshots

After Step 1: 01

After Step 3: 02

Reproduction Link

APopatanasov commented 4 years ago

HI @ryanthtra,

Using the provided description I was able to easily reproduce the described by you issue.

It is caused by the virtualization of the control - not all rows are rendered. Because of that when using the Shift + press extended selection only the currently rendered rows are taken in account by the selection mechanism.

The extended selection is working with some internal for the DataGrid APIs and because of that I cannot suggest any workaround for this issue.

However, if you are interested on working on this issue and apply a fix by yourself I can provide you some more detailed information.

The problematic code comes from a method called SelectRangeCells part of the selection service of the the DataGrid. Inside it using the CellsController the cells that need to be selected are taken - here the CellsController contains only the rendered cell. Basically, that method needs to be re-written. Maybe in order to work as expected the DataView of the Grid should be used (it contains all the items not only the rendered ones) - here is a sample code that might work:

private void SelectRangeCells(int row, int column = -1)
{
    var item = this.dataView.Items[row]; // this is this.Owner.GetDataView()
    switch (this.Owner.SelectionUnit)
    {
        case DataGridSelectionUnit.Row:
            this.SelectItem(item, true, false);
            break;
        case DataGridSelectionUnit.Cell:
            var cellInfo = new DataGridCellInfo(item, this.Owner.Model.VisibleColumns.ElementAt(column));
            this.SelectCellInfo(cellInfo, true, false);
            break;
        default:
            throw new ArgumentException("Unknown selection unit type", "this.Owner.SelectionUnit");
    }
}

This is just a sample code and should be tested further. Feel free to open a pull request with a potential fix - I will be glad to review it and provide you with a feedback.

If you need some more information do not hesitate to let me know.

Zofware commented 3 years ago

@APopatanasov Thanks for that code fragment. I'll give it a try and prepare a PR if it checks out.

Zofware commented 3 years ago

Seems to work mostly as-is. PR inbound.

Zofware commented 3 years ago

See PR https://github.com/telerik/UI-For-UWP/pull/465.