Unplanned
Last Updated: 03 Jul 2025 15:06 by Emanuele
Bert
Created on: 14 Feb 2024 10:54
Category: VirtualGrid
Type: Feature Request
2
RadVirtualGrid: Add possibility to deselect row on Ctrl key pressed
When the user clicks an already selected row while pressing the Ctrl key, the row should be removed from the current selection.
6 comments
Emanuele
Posted on: 03 Jul 2025 15:06

Hello Dinko,

this way it works.

Thank you very much.

 

Emanuele

ADMIN
Dinko | Tech Support Engineer
Posted on: 02 Jul 2025 12:23

Hello Emanuele,

I will assist you today. I have checked the code, and indeed, the SelectionChanged event is not called. Keep in mind that this is custom code and it may not work in all cases.

What I can suggest here is to subscribe to this.radVirtualGrid1.VirtualGridElement.Selection.SelectionChanged of the Selection behavior:

this.radVirtualGrid1.VirtualGridElement.Selection.SelectionChanged += Selection_SelectionChanged;

In the HandleMouseDown() method, we are using the AddSelectedRegions() method to add a region. This method does not call the SelectionChanged event. You can consider using the this.GridElement.Selection.BeginSelection() method:

foreach (SelectionRegion item in regions)
{
    this.GridElement.Selection.BeginSelection(item.Top,item.Left,this.GridElement.MasterViewInfo,true);
    //this.GridElement.Selection.AddSelectedRegions(item);
}

Now the SelectionChanged event is called, and the HasSelection property returns true when you have selected rows and false when no rows are selected.

Regards,
Dinko | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Emanuele
Posted on: 26 Jun 2025 09:58

Hello Nadya,

another issue is that after a row has been deselected the value of this.GridElement.Selection.HasSelection is false and I cannot copy the rows anymore...

 ...

this.GridElement.Selection.ClearSelection(); foreach (SelectionRegion item in regions) { this.GridElement.Selection.AddSelectedRegions(item); } var lastRegion = regions.Last(); this.GridElement.CurrentCell = new VirtualGridCellInfo(lastRegion.Left, lastRegion.Top, this.GridElement.MasterViewInfo); this.GridElement.TableElement.SynchronizeRows(true, true);

// this.GridElement.Selection.HasSelection == false return true;

...

 

Thank you,

Emanuele

Emanuele
Posted on: 26 Jun 2025 08:38

Hello Nadya,

thank you for the response. I still have one issue because I need to update the number of selected rows and when you deselect the rows with CTRL+click

...

this.GridElement.Selection.ClearSelection(); //--> SelectionChanged FIRED foreach (SelectionRegion item in regions) { this.GridElement.Selection.AddSelectedRegions(item); //--> SelectionChanged NOT NOT FIRED }

...

the callback SelectionChanged is not fired when adding the regions.

Is there a way to fire the event programmatically?

 

Thank you,

Emanuele

ADMIN
Nadya | Tech Support Engineer
Posted on: 24 Jun 2025 10:32

Hello, Emanuele,

Upon checking, this feature request is still not implemented as a built-in feature in RadVirtualGrid. You can vote for this item to increase its priority.

However, it is possible to deselect a row in the virtual grid when the Ctrl key is pressed by creating a custom VirtualGridInputBehavior. More information is available here: InputBehavior - RadVirtualGrid - Telerik UI for WinForms

Please refer to the following code snippet:

this.radVirtualGrid1.VirtualGridElement.InputBehavior = new CustomVirtualGridInputBehavior(this.radVirtualGrid1.VirtualGridElement);

public class CustomVirtualGridInputBehavior : VirtualGridInputBehavior
{
    public CustomVirtualGridInputBehavior(RadVirtualGridElement gridElement)
        : base(gridElement)
    {
    }
    public override bool HandleMouseDown(MouseEventArgs args)
    {
        VirtualGridCellElement cell = this.GridElement.ElementTree.GetElementAtPoint(args.Location) as VirtualGridCellElement;
        if (cell == null)
        {
            return base.HandleMouseDown(args);
        }
        bool ctrl = (Control.ModifierKeys & Keys.Control) != 0 && this.GridElement.Selection.Multiselect;
        if (!this.GridElement.Selection.RowContainsSelection(cell.RowIndex, this.GridElement.MasterViewInfo))
        {
            return base.HandleMouseDown(args); ;
        }
        if (cell != null && args.Button == System.Windows.Forms.MouseButtons.Left && ctrl)
        {
            List<SelectionRegion> regions = new List<SelectionRegion>();
            foreach (SelectionRegion item in this.GridElement.Selection.SelectedRegions)
            {
                if (cell.RowIndex != item.Top)
                {
                    regions.Add(item);

                }
            }
            this.GridElement.Selection.ClearSelection();

            foreach (SelectionRegion item in regions)
            {
                this.GridElement.Selection.AddSelectedRegions(item);
            }
            var lastRegion = regions.Last();
            this.GridElement.CurrentCell = new VirtualGridCellInfo(lastRegion.Left, lastRegion.Top, this.GridElement.MasterViewInfo);
            this.GridElement.TableElement.SynchronizeRows(true, true);
            return true;
        }
        return base.HandleMouseDown(args);
    }
}

I hope this helps. If you have other questions, please let me know. 

Regards,
Nadya | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Emanuele
Posted on: 24 Jun 2025 09:57

Good morning,

do you have any news on this feature? Or any workarounds?

Thank you.

 

Emanuele