Hello Dinko,
this way it works.
Thank you very much.
Emanuele
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.
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
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
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.
Good morning,
do you have any news on this feature? Or any workarounds?
Thank you.
Emanuele