Articles in this section
Category / Section

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

2 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

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