Articles in this section
Category / Section

How to synchronize the scrolling of one to another in the WPF SfDataGrid?

4 mins read

By default, it is not possible to scroll one SfDataGrid through another. However, it can be achieved by using the ScrollChanged event of the SfDataGrid. You can wire the ScrollChanged event in the loaded event of the Datagrid1 like the following code example.

XAML

void Datagrid1_Loaded(object sender, RoutedEventArgs e)
 {
            this.Datagrid1.GetVisualContainer().ScrollOwner.ScrollChanged += ScrollOwner1_ScrollChanged;
 }

 

C#

        //ScrollChanged event of the ScrollViewer in Datagrid1.
        void ScrollOwner1_ScrollChanged(object sender, ScrollChangedEventArgs e)
        {
            //Sets the Horizontal offset value when horizontally scrolled.
            if (e.HorizontalChange > 0 || e.HorizontalChange < 0)
            {
                 this.Datagrid2.GetVisualContainer().SetHorizontalOffset(e.HorizontalOffset);
            }
            //Sets the Horizontal offset value when horizontally scrolled.
            if (e.VerticalChange > 0 || e.VerticalChange < 0)
            {
                 this.Datagrid2.GetVisualContainer().SetVerticalOffset(e.VerticalOffset);
            }
        }

 

As given in the above code example, you can set the Horizontal or Vertical offset based on its corresponding Horizontal or Vertical change while scrolling.  Likewise, you can wire the ScrollChanged event for Datagrid2 and set the Horizontal and Vertical offset.

 

Note:

The above code example is only applicable for the WPF platform. For WinRT, UWP refer to the following link.

 

Sample Links:

 

WPF

WRT

UWP


Conclusion

I hope you enjoyed learning about how to synchronize the scrolling of one to another in the WPF SfDataGrid.

You can refer to our WPF SfDataGrid feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WPF SfDataGrid example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!



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