Prevent right-click from causing cell to enter edit mode
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.
SIGN IN To post a reply.
5 Replies
GG
Gowtham Gopalsamy
Syncfusion Team
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
BB
Brian Bell
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
GG
Gowtham Gopalsamy
Syncfusion Team
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
BB
Brian Bell
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
SJ
Sathiyathanam Jeyakumar
Syncfusion Team
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
SIGN IN To post a reply.
- 5 Replies
- 3 Participants
-
BB Brian Bell
- Sep 25, 2019 09:54 PM UTC
- Dec 30, 2020 10:24 AM UTC