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

Set ScrollBar.LargeChange on SfDataGrid

Hi,
I have a requirement where I need to change the number of rows that are scrolled down/up when clicking on the vertical scrollbar for the SfDataGrid.

Currently, if I have, say 10 records in view, and I click the scrollbar under the slider, the SfDataGrid moves down 9 records. I want to move down 10 rows at a time so that each click shows 10 new records, rather than 9 new records and one from the previous set of records. I have tried the following code but it doesn't seem to have any effect...

        private void SfDataGrid_FilterItemsPopulated(object sender, Syncfusion.UI.Xaml.Grid.GridFilterItemsPopulatedEventArgs e)
        {
            ScrollViewer scrollViewer = sfDataGrid.GetVisualContainer().ScrollOwner;
            ScrollBar verticalScrollBar = scrollViewer.Template.FindName("PART_VerticalScrollBar", scrollViewer) as ScrollBar;
            verticalScrollBar.LargeChange = 240;
        }

Cheers,
James.

---

Just want to add that changing the value '240' to any other value makes no difference!

4 Replies

JR James Randle November 12, 2018 10:47 AM UTC

Hi,
Any word on how to accomplish this requirement?

Cheers,
James.


SP Shobika Palani Syncfusion Team November 13, 2018 11:17 AM UTC

Hi James, 

Thank you for contacting Syncfusion Support. 

We have analyzed your query to scroll multiple rows on clicking Up/Down in vertical scrollbar. You can achieve this requirement using VisualContainer.LineUp/VisualContainer.LineDown methods as like below code snippet 

private void AssociatedObject_Loaded(object sender, System.Windows.RoutedEventArgs e) 
        { 
            this.AssociatedObject.GetVisualContainer().ScrollOwner.PreviewMouseLeftButtonDown += ScrollOwner_PreviewMouseLeftButtonDown; 
        } 
 
        private void ScrollOwner_PreviewMouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) 
        { 
            RepeatButton repeatButton = null; 
            object value = null; 
            var source = e.OriginalSource; 
            while (repeatButton == null && source != null) 
            { 
                var parent = source.GetType().GetProperty("InternalVisualParent", BindingFlags.Instance | BindingFlags.NonPublic); 
                value = parent.GetValue(source); 
                source = value; 
                repeatButton = value as RepeatButton; 
            } 
 
            if (repeatButton != null) 
            { 
                var name = ((RoutedCommand)repeatButton.Command).Name; 
                if (name == "LineUp") 
                { 
                    for (int i = 1; i < 10; i++) 
                        this.AssociatedObject.GetVisualContainer().LineUp(); 
                } 
                else if (name == "LineDown") 
                { 
                    for (int i = 1; i < 10; i++) 
                        this.AssociatedObject.GetVisualContainer().LineDown(); 
                } 
            } 
        } 

Please find sample for the same from below link 
Sample Link: 

Please let us know if you need further assistance on this. 

Regards, 
Shobika. 



JR James Randle November 13, 2018 11:44 AM UTC

Hi,
Thanks for your reply.

That works if i click the up and down arrow buttons, but I would also like to have the same functionality if i click the area between the scrollbar slider and the up/down arrow buttons (see attached file for explanatory image).

Cheers,
James.



Attachment: ClickScrollbar_7dd6799f.zip


JN Jayaleshwari N Syncfusion Team November 14, 2018 09:56 AM UTC

Hi James,  
 
We have checked the query “To scroll multiple rows on clicking area between Up/Down arrows in vertical scrollbar”. You can achieve your requirement by calling VisualContainer.LineUp/VisualContainer.LineDown methods for PageUp and PageDown repeat button. 
  
private void ScrollOwner_PreviewMouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)  
        {  
            RepeatButton repeatButton = null;  
            object value = null;  
            var source = e.OriginalSource;  
            while (repeatButton == null && source != null)  
            {  
                var parent = source.GetType().GetProperty("InternalVisualParent", BindingFlags.Instance | BindingFlags.NonPublic);  
                value = parent.GetValue(source);  
                source = value;  
                repeatButton = value as RepeatButton;  
            }  
  
            if (repeatButton != null)  
            {  
                var name = ((RoutedCommand)repeatButton.Command).Name; 
               if (name == "LineUp" || name=="PageUp") 
                { 
                    for (int i = 0; i < 10; i++) 
                        this.AssociatedObject.GetVisualContainer().LineUp(); 
                    e.Handled = true; 
                } 
                else if (name == "LineDown" || name=="PageDown") 
                { 
                    for (int i = 0; i < 10; i++) 
                        this.AssociatedObject.GetVisualContainer().LineDown(); 
                    e.Handled = true; 
                }             
   }          
}  
 
We have attached the modified sample for your reference and you can download the same from the following location. 
 
 
Please let us know if you would require further assistance. 
 
Regards,  
Jayaleshwari N. 


Loader.
Live Chat Icon For mobile
Up arrow icon