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.

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

Thread ID:

Created:

Updated:

Platform:

Replies:

125699 Sep 4,2016 12:00 PM Jul 14,2017 02:55 AM WPF 8
loading
Tags: SfDataGrid
Vidar Lund
Asked On September 4, 2016 12:00 PM

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.

Cheers,
Vidar

Gobikrishnan Murugesan [Syncfusion]
Replied On September 5, 2016 02:08 AM

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; 
                sfdatagrid.ScrollInView(sfdatagrid.SelectionController.CurrentCellManager.CurrentRowColumnIndex); 
                        
            })); 
 
        } 
    } 
} 
 
 
Sample: 
 
Please let us know if you have any query. 
 
Regards, 
Gobikrishnan  
 


Vidar Lund
Replied On September 5, 2016 03:26 AM

Wow,

Thanks Gobikrishnan!
This works straight out of the box!

Best regards,
Vidar

Jai Ganesh S [Syncfusion]
Replied On September 6, 2016 12:22 AM

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


Alviero Chiacchieroni
Replied On July 12, 2017 12:44 PM

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


Muthukumar Kalyanasundaram [Syncfusion]
Replied On July 13, 2017 09:39 AM

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) 
    {               
        if(SelectionHelper.CheckShiftKeyPressed()) 
            base.ProcessPointerPressed(args, rowColumnIndex); 
        else 
            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.   
 
Regards, 
Muthukumar K 


Alviero Chiacchieroni
Replied On July 13, 2017 10:17 AM

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.


Alviero Chiacchieroni
Replied On July 13, 2017 01:33 PM

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!


Muthukumar Kalyanasundaram [Syncfusion]
Replied On July 14, 2017 02:55 AM

Hi Alviero, 

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

Regards, 
Muthukumar K 


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.

;