This is a migrated thread and some comments may be shown as answers.

Shift-Clicking on GridViewSelectColumn CheckBox

3 Answers 348 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 19 Nov 2020, 09:45 PM

Hello!

We are experiencing difficulty supporting the RadGridView's Multi-Selection capabilities when our end-users shift-click directly on the checkbox inside the cell of a GridViewSelectColumn. 

What we expect to see is everything in between the originally selected row and the shift-clicked row would be selected. What we see happen is the original row getting selected and only the shift-clicked row getting marked as selected. 

 

What can we do to make sure the act of shift-clicking directly on the checkbox that comes with the GridViewSelectColumn yields the same multi-selection behavior we see when shift-clicking on any other portion of the cell?

3 Answers, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 24 Nov 2020, 07:52 PM

Hello Alex,

The described behavior appears because clicking on the CheckBox element in the GridViewSelectColumn is stealing the focus from RadGridView, thus the default Shift+Click selection logic doesn't kick-in. Instead, only the clicked row is added into the current selection.

To achieve your requirement, you can create a custom GridViewSelectColumn and override its CreateCellElement() method. There you can get the CheckBox and subscribe to its Click event. In the handler, you can execute the selection manually by using the SelectCellRegion() or  SelectItemsRange() method. For example:

public class CustomSelectColumn : GridViewSelectColumn
{
	public override FrameworkElement CreateCellElement(GridViewCell cell, object dataItem)
	{
		var checkBox = (CheckBox)base.CreateCellElement(cell, dataItem);
		checkBox.Click += CheckBox_Click;
		return checkBox;
	}

	private void CheckBox_Click(object sender, RoutedEventArgs e)
	{
		var gridView = (RadGridView)this.DataControl;
		// use the SelectCellRegion or SelectItemsRange method to select the corresponding items range
	}
}

I hope this helps.

Regards,
Martin Ivanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Thom
Top achievements
Rank 1
commented on 18 Jan 2024, 05:36 PM

Has this been fixed in the newer version of UI for WPF?

We use a strict MVVM design and avoid code-behind. Is there a way to implement this functionality in the XAML?

thanks,

Thom

Martin Ivanov
Telerik team
commented on 19 Jan 2024, 12:29 PM

Hello Thom,

This is not fixed, because is not considered a bug, but more of an expected behavior in the WPF framework.

About the strict MVVM design, the suggested solution doesn't use any code-behind, so it doesn't break the MVVM pattern. The suggestion is to create a custom column class, that is not related to the code-behind.

As for a XAML alternative of this solution, there is no such. Implementing this will require to work with the selection API, which requires to write C# code.

Alex
Top achievements
Rank 1
commented on 19 Jan 2024, 02:16 PM

Hi Martin,

How is it considered a feature when multi-selection does not work as expected when the user shift-clicks directly on the checkbox? How can I convince Telerik that it should behave the same as if I shift-clicked on a different cell in the grid for multiple rows?

Martin Ivanov
Telerik team
commented on 22 Jan 2024, 11:05 AM

Hey Alex, if you believe that this should be treated as a bug, you can create a new report in the feedback portal. This way it will undergo a review and it can be discussed and investigated further internally.
0
Alex
Top achievements
Rank 1
answered on 25 Nov 2020, 04:13 PM

Hi Martin,

Your suggestion seems to be a step in the right direction, but we're still having trouble.

The documentation for using "SelectCellRegion()" is scarce. There doesn't appear to be any example or instruction that shows how to get the indices of the "origin cell" from the API nor those of the selected cell. The examples that do exist use hard-coded integers.

The documentation for using "SelectItemsRange()" is in better shape, but we are running into an issue where the range always starts from the top row.

Here's the code we put into the handler for the Click event.

private void CheckBox_Click(object sender, RoutedEventArgs e)
{
    var checkBox = (CheckBox)sender;
    var gridView = (RadGridView)DataControl;
 
    if (checkBox != null && KeyboardModifiers.IsShiftDown)
    {
        var gridRow = checkBox.ParentOfType<GridViewRow>();
 
        if (gridRow != null)
        {
            gridView.SelectItemsRange(gridView.Items.IndexOf(gridView.SelectedItem), gridRow.Item, false);
        }
    }
}
0
Alex
Top achievements
Rank 1
answered on 25 Nov 2020, 04:17 PM
Nevermind, I mixed an Index with an object while using "SelectItemsRange"
Tags
GridView
Asked by
Alex
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Alex
Top achievements
Rank 1
Share this question
or