Articles in this section
Category / Section

How to scroll multiple items for one mouse wheel in WinForms DataGrid (SfDataGrid)?

1 min read

 

By default, in SfDataGrid you can scroll only one item while doing MouseWheel. But you can scroll multiple items while doing MouseWheel by handling the MouseWheel event in SfDataGrid.TableControl. You can achieve scroll multiple items while doing MouseWheel by increase and decrease the current position of the scroll box on the scrollbar control based on the delta value.

sfDataGrid1.TableControl.MouseWheel += OnTableControl_MouseWheel;private void OnTableControl_MouseWheel(object sender, MouseEventArgs e){
            if (e.Delta == 0)
                return;
           
            var smallChange = sfDataGrid1.TableControl.ScrollRows.ScrollBar.SmallChange;
            if (e.Delta > 0)
                sfDataGrid1.TableControl.ScrollRows.ScrollBar.Value -= (4 * smallChange);
            else
                sfDataGrid1.TableControl.ScrollRows.ScrollBar.Value += (4 * smallChange);
 
            this.sfDataGrid1.TableControl.UpdateScrollBars();
            this.sfDataGrid1.TableControl.Invalidate();
}

ScrollMultipleItem when mouse wheel in SfDataGrid

View Sample in GitHub

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied