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.
Unfortunately, activation email could not send to your email. Please try again.

SfDataGrid - Prevent right click from selecting row

Thread ID:

Created:

Updated:

Platform:

Replies:

123795 Apr 21,2016 06:45 PM May 5,2016 10:44 AM UWP 3
loading
Tags: SfDataGrid
Arvin
Asked On April 21, 2016 06:45 PM

Hi,

Is there any way to prevent the right click from changing row selection in a SfDataGrid? I just want to use it for context menus.

Jai Ganesh S [Syncfusion]
Replied On April 22, 2016 01:13 AM

Hi Arvin,

You can prevent the right click from changing row selection in SfDataGrid by wiring the PreviewMouseDown event like below,

this.SfdataGrid.PreviewMouseDown+=SfdataGrid_PreviewMouseDown;


void SfdataGrid_PreviewMouseDown(object sender, MouseButtonEventArgs e)

        {

            if(e.ChangedButton==MouseButton.Right)

            {

                e.Handled = true;

            }

        }


Regards,

Jai Ganesh S


Arvin
Replied On May 4, 2016 07:15 PM

There doesn't seem to be an event called PreviewMouseDown. 

I have a datagrid declared in XAML

<syncfusionGrid:SfDataGrid x:Name="TrackListUi"  ...

in my page's constructor I try to subscribe to the event as you suggested but PreviewMouseDown isn't one of the events in the list. Any suggestions?

Jai Ganesh S [Syncfusion]
Replied On May 5, 2016 10:44 AM

Hi Arvin, 
 
Sorry for the inconvenience. 
You can prevent the right click from changing row selection in SfDataGrid by customizing the SelectionController and overriding the ProcessPointerPressed like below, 
this.datagrid.SelectionController = new GridSelectionControllerExt(datagrid); 
 
public class GridSelectionControllerExt : GridSelectionController 
    { 
 
        public GridSelectionControllerExt(SfDataGrid dataGrid) 
            : base(dataGrid) 
        { } 
 
        protected override void ProcessPointerPressed(PointerRoutedEventArgs args, RowColumnIndex rowColumnIndex) 
        { 
            var properties = args.GetCurrentPoint(DataGrid).Properties; 
            if (properties.IsRightButtonPressed) 
            { 
                args.Handled = true; 
            } 
            else 
                base.ProcessPointerPressed(args, rowColumnIndex); 
        } 
    } 
 
Sample
Regards, 
Jai Ganesh S 


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.

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.

;