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: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

SfDataGrid - Prevent right click from selecting row

Thread ID:

Created:

Updated:

Platform:

Replies:

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

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 05:13 AM UTC

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 11:15 PM UTC

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 02:44 PM UTC

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.

Please sign in to access our forum

or the page will be automatically redirected to 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

;