Preventing the right click from changing row selection in a SfDataGrid

Is there any way to prevent the right click from changing row selection in a SfDataGrid (Windows Forms)?

I tried to rewrite the UWP solution (https://www.syncfusion.com/forums/123795/sfdatagrid-prevent-right-click-from-selecting-row) but there is no PreviewMouseDown event and SelectionController does not have ProcessPointerPressed equivalent.

1 Reply

VS Vijayarasan Sivanandham Syncfusion Team December 7, 2020 03:44 PM UTC

Hi Piotr,

Thanks for contacting Syncfusion support.

Based on provided information your requirement can be achieved by customization the RowSelectionController in SfDataGrid. Please refer the below code snippet for your reference,

 
sfDataGrid.SelectionController = new CustomSelectionController(this.sfDataGrid); 
 
public class CustomSelectionController : RowSelectionController 
{ 
        SfDataGrid sfDataGrid; 
 
        public CustomSelectionController(SfDataGrid sfDataGrid) 
            : base(sfDataGrid) 
        { 
            this.sfDataGrid = sfDataGrid; 
        } 
        
        protected override void HandlePointerOperations(DataGridPointerEventArgs args, RowColumnIndex rowColumnIndex) 
        { 
           if(args.Operation == PointerOperation.Pressed) 
           { 
                var mouseEventargs = args.OriginalEventArgs as MouseEventArgs; 
                if (mouseEventargs.Button == MouseButtons.Right) 
                { 
                    this.ResumeUpdates(); 
                    return; 
                } 
           }                      
               base.HandlePointerOperations(args, rowColumnIndex); 
        } 
} 
We hope this helps. Please let us know, if you require further assistance on this.

Regards,
Vijayarasan S
 


Loader.
Up arrow icon