We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Prevent right-click from causing cell to enter edit mode

Thread ID:

Created:

Updated:

Platform:

Replies:

147857 Sep 25,2019 09:54 PM UTC Sep 30,2019 12:25 PM UTC WPF 3
loading
Tags: SfDataGrid
Brian Bell
Asked On September 25, 2019 09:54 PM UTC

I am using SfDataGrid w AllowEditing = "True" and EditTrigger = "OnTap". I am using MVVM and XAML.

I wish to prevent right-click from causing cells to go into edit mode. Right-click should still control selection and context-menus, just not edit mode.

Is there a way to do this?

Thanks.


Gowtham Gopalsamy [Syncfusion]
Replied On September 26, 2019 01:40 PM UTC

Hi Brian,   
   
Thanks for your patience. 
You can achieve your requirement to prevent the edit mode when right clicking in SfDataGrid by customizing the SelectionController and overriding the ProcessPointerPressed. 
Please refer the below code snippet, 
 
this.datagrid.SelectionController = new GridSelectionControllerExt(datagrid); 
 
public class GridSelectionControllerExt : GridSelectionController 
{ 
 
    public GridSelectionControllerExt(SfDataGrid dataGrid) 
        : base(dataGrid) 
    { } 
 
    protected override void ProcessPointerPressed(MouseButtonEventArgs args, RowColumnIndex rowColumnIndex) 
    { 
        if (args.ChangedButton == MouseButton.Right) 
        { 
            args.Handled = true; 
        } 
        else 
            base.ProcessPointerPressed(args, rowColumnIndex); 
    } 
} 
 
 
Please refer the below sample link, 
 
 
Please refer the below KB link, 
 
 
Please let us know if you have any concern.  
 
Regards,     
Gowtham     
 


Brian Bell
Replied On September 27, 2019 03:08 PM UTC

This isn't right. Right-click should still select the row, it just shouldn't enter edit mode in the cell.

The solution given prevents the selection of the row.

Thanks

Gowtham Gopalsamy [Syncfusion]
Replied On September 30, 2019 12:25 PM UTC

Hi Brian , 
 
Thanks for your patience. 
 
You can achieve your requirement to prevent the edit mode when right clicking in SfDataGrid and select the particular row while pressing the right click  by customizing the SelectionController and overriding the ProcessPointerPressed. 
 
Please refer the below code snippet, 
 
public class GridSelectionControllerExt : GridSelectionController 
{ 
 
    public GridSelectionControllerExt(SfDataGrid dataGrid) 
        : base(dataGrid) 
    { } 
 
    protected override void ProcessOnTapped(MouseButtonEventArgs e, RowColumnIndex currentRowColumnIndex) 
    { 
        if (e.ChangedButton == MouseButton.Left) 
            base.ProcessOnTapped(e, currentRowColumnIndex); 
        else 
            e.Handled = true; 
    } 
} 
 
Please refer the below sample link 
 
 
Please let us know, if you require further assistance on this.    
     
Regards,    
Gowtham    
 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon