)
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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

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

Platform: WPF |
Control: SfDataGrid |
Published Date: July 27, 2015 |
Last Revised Date: February 5, 2016 |
.NET Framework: 4.5.1
Tags: scrollviewer

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

 

C#

 

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

2X faster development

The ultimate WPF UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment
Comments
Zeljko Lazic
Apr 12, 2019

Is there a similar example without referring to the grids in the code behind i.e. MVVM?

Reply
Shobika Palani [Syncfusion]
Apr 15, 2019

Hi Zeljko,

We have analyzed your query to synchronize the scrolling between two SfDataGrid in MVVM pattern. And you can achieve this requirement by writing behavior for each datagrid as like below code snippet,

C#:

public class FirstSfDataGridBehavior : Behavior
    {
        protected override void OnAttached()
        {
            base.OnAttached();
            this.AssociatedObject.Loaded += AssociatedObject_Loaded;
        }

        private void AssociatedObject_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
            this.AssociatedObject.GetVisualContainer().ScrollOwner.ScrollChanged += ScrollOwner_ScrollChanged;
        }

        private void ScrollOwner_ScrollChanged(object sender, System.Windows.Controls.ScrollChangedEventArgs e)
        {
            SfDataGrid otherDataGrid = Application.Current.MainWindow.FindName("Datagrid2") as SfDataGrid;

            //Set the Vertical offset for Grid1 and Grid2 when we Vertically scroll the Grid
            if (e.HorizontalChange > 0 || e.HorizontalChange < 0)
            {
                otherDataGrid.GetVisualContainer().SetHorizontalOffset(e.HorizontalOffset);
            }

            //Set the Vertical offset for Grid1 and Grid2 when we Vertically scroll the Grid
            if (e.VerticalChange > 0 || e.VerticalChange < 0)
            {
                otherDataGrid.GetVisualContainer().SetVerticalOffset(e.VerticalOffset);
            }
        }
    }

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

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

Regards, Shobika.

Thierry Delucinges
Oct 03, 2019

Hi,

Same problem, I tried with the behavior version but on AssociatedObject_Loaded, this.AssociatedObject.GetVisualContainer() return null… I've also set ScrollViewer.HorizontalScrollBarVisibility="Visible" in xaml in case of… but… Regards.

Reply
Mohanram Anbukkarasu [Syncfusion]
Oct 07, 2019

Hi Thierry,

Thanks for your update.

We have checked the reported case in our sample. But unfortunately we are unable to reproduce the reported issue in our end. Please ensure whether you have any other customization in your sample and let us know if any. It will be helpful for us to find the cause for the issue and provide a proper solution.

Regards, Mohanram A.

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon