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

Shift-Clicking on GridViewSelectColumn CheckBox

3 Answers 40 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/.

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