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. Image for the cookie policy date
close icon

Automatically selecting row when howering above it while pressing the mouse button.

Some default WPF controls have this feature, like ListView. You simply hold the left mousebutton and slide the mouse over the rows and they are automatically selected. With SfDataGrid you need to click again.


8 Replies

GM Gobikrishnan Murugesan Syncfusion Team September 5, 2016 06:08 AM UTC

Hi Vidar, 
Thank you for contact Syncfusion support. 
We have analysed your query. Currently our SfDataGrid does not have direct support for ListView like mousehover selection. You can achieve your requirement by handle Mouse move event of SfDatagrid as like below the workaround, 
void sfdatagrid_MouseMove(object sender, MouseEventArgs e) 
    if (e.MouseDevice.LeftButton == MouseButtonState.Pressed) 
        //With the help of VisualContainer ,you can get the row and column index based on the mouse move pointer position 
        var visualcontainer = this.sfdatagrid.GetVisualContainer(); 
        // Gets the exact position where the mouse pointer is moved  
        var point = e.GetPosition(visualcontainer); 
        //Here you can get the row and column index based on the pointer position by using PointToCellRowColumnIndex() method 
        var rowColumnIndex = visualcontainer.PointToCellRowColumnIndex(point); 
        //When the rowindex is zero , the row will be header row  
        if (!rowColumnIndex.IsEmpty) 
            var data = this.sfdatagrid.GetRowGenerator().Items.FirstOrDefault(x => x.RowIndex == rowColumnIndex.RowIndex); 
            sfdatagrid.Dispatcher.BeginInvoke(new Action(() => 
                sfdatagrid.SelectedItem = data.RowData; 
Please let us know if you have any query. 

VL Vidar Lund September 5, 2016 07:26 AM UTC


Thanks Gobikrishnan!
This works straight out of the box!

Best regards,

JG Jai Ganesh S Syncfusion Team September 6, 2016 04:22 AM UTC

Hi Vidar, 
Thank you for the update. 
Please let us know if you need further assistance on this. 
Jai Ganesh S 

AC Alviero Chiacchieroni July 12, 2017 04:44 PM UTC

I've searched a lot inside the forum before to write.

I need to disable the selection when the left mouse button is down and the mouse is dragged.

Is it possible to do it in an SfDataGrid?

The result that I want to achieve is that the user can select rows by mouse click and at least with the combination mouse click + the shift key.

This feature that I discover by a friend is a danger for certain type of users

MK Muthukumar Kalyanasundaram Syncfusion Team July 13, 2017 01:39 PM UTC

Hi Alviero, 
Thanks for the update. 
We have checked your query. We couldn’t understand your requirement clearly. Based on our understanding, we have prepared the sample. In the sample, you have select the row by pressing Shift key. For your reference, we have attached sample in the below location, 
Code Snippet: 
this.sfGrid.SelectionController = new GridSelectionControllerExt(this.sfGrid); 
internal class GridSelectionControllerExt : GridSelectionController 
    public GridSelectionControllerExt(SfDataGrid datagrid) : base(datagrid) 
    protected override void ProcessPointerPressed(MouseButtonEventArgs args, RowColumnIndex rowColumnIndex) 
            base.ProcessPointerPressed(args, rowColumnIndex); 
            args.Handled = true; 
If your requirement is different from this, could you please share some more information about your requirement clearly ?.  This would be more helpful for us to proceed further.   
Muthukumar K 

AC Alviero Chiacchieroni July 13, 2017 02:17 PM UTC

Hi, I've just give a try at your sample but is not that I want to do.

I'm understood that my problem is the   SelectionMode="Multiple" of the DataGrid.

When I set Multiple instead "Row" in the SelectionMode the user can select multiple rows by hold down the left button and moving down or up the mouse.

I want to avoid it and give the multiple selection only by a click of the left button.

The click of the left button + the shift key is welcome but what I want to eliminate is the selection with the button hold while the mouse is moved down or up.

AC Alviero Chiacchieroni July 13, 2017 05:33 PM UTC

I'm happy!!!

I've solved my trouble myself.

Many thanks for your sample that give me the right inspiration.

I've thinked to go browsing the object class sfgrid from inside Visual Studio and found the solution near the method you have overrided.

My solution that work perfectly for me is:

           protected override void ProcessPointerMoved(System.Windows.Input.MouseEventArgs args, Syncfusion.UI.Xaml.ScrollAxis.RowColumnIndex rowColumnIndex)
                args.Handled = true;

With this override in your example and with the "SelectionMode" set to Multiple like in my application under development now it work!

MK Muthukumar Kalyanasundaram Syncfusion Team July 14, 2017 06:55 AM UTC

Hi Alviero, 

You are welcome. Please let us know if you need further assistance. 

Muthukumar K 

Live Chat Icon For mobile
Up arrow icon