How to synchronize the scrolling of one to another in the SfDataGrid?
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.
The above code example is only applicable for the WPF platform. For WinRT, UWP refer to the following link.
Sample Links: