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 Dec 30,2020 10:24 AM UTC WPF 5
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    
 


Brian Bell
Replied On December 29, 2020 08:08 PM UTC

Hi - I am revisiting this issue. The solution provided works insofar as it selects the row and doesn't cause a cell to enter edit mode.

It seems to disable the SfDataGrid's ContextMenu, though. 

On right-click, the following should happen:
1. The row is selected.
2. The cell does not enter edit mode.
3. The context menu appears.

How can I modify this to get the context menu to appears?

Thanks

Sathiyathanam Jeyakumar [Syncfusion]
Replied On December 30, 2020 10:24 AM UTC

Hi Brain 
We have prepared the sample as per your requirement. You can disable editing of gridcell, when right click the cell with EditTrigger as ‘OnTap’ by set CurrentCellBeginEditEventArgs.Cancel as true in  CurrentCellBeginEditEvent. Now ,when you right click the cell the row will be selected and the cell doen’t enter the edit mode and contextmenu also to be shown. Please refer the below code snippets. 
public class SfDataGridBehavior:Behavior<SfDataGrid> 
{ 
    SfDataGrid dataGrid = null; 
    bool isRighClickButtonEnabled = false; 
    protected override void OnAttached() 
    { 
        base.OnAttached(); 
        this.dataGrid = this.AssociatedObject as SfDataGrid; 
        this.dataGrid.CellTapped += DataGrid_CellTapped; 
        this.dataGrid.CurrentCellBeginEdit += DataGrid_CurrentCellBeginEdit; 
 
    } 
 
    private void DataGrid_CurrentCellBeginEdit(object sender,  CurrentCellBeginEditEventArgs e) 
    { 
        if (isRighClickButtonEnabled) 
            e.Cancel = true; 
    } 
 
    private void DataGrid_CellTapped(object sender, GridCellTappedEventArgs e) 
    { 
        if(e.ChangedButton == System.Windows.Input.MouseButton.Right) 
        { 
            isRighClickButtonEnabled = true; 
        } 
        else 
        { 
            isRighClickButtonEnabled = false; 
        } 
    } 
} 


Please refer the below UG link for get more information about editing and editing customizations. 

Regards, 
Sathiyathanam 


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