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
close icon

Synchronize to grid scrolling

I have 2 grids on a window.   When I scroll a grid I want to programmatically scroll the second one.   Both grids have the same number of columns/rows....  Basically how to keep them showing the same row/column?

1 Reply

MM Muthalagu M Syncfusion Team May 12, 2015 03:02 AM UTC

Hi Harlan,

Thank you for using Syncfusion Products.

We have analysed your query and you can achieve your requirement with the help of VisualContainer in SfDataGrid. We have prepared the sample also and you can download the sample from the following location,

Sample: ScrollingTwoGridAtSameTime.zip


In this sample, we have used the same number of row and column count in two grids. With the help of VisualContainer in both the grids, we have accessed the internal ScrollViewer and scroll the grids based on their offset value in ScrollChanged event of ScrollViewer. Please find the code snippet below,

//ScrollChanged event of ScrollViewer in Datagrid1

void ScrollOwner1_ScrollChanged(object sender, ScrollChangedEventArgs e)

{

if (e.HorizontalChange > 0 || e.HorizontalChange < 0)

{

this.Datagrid1.GetVisualContainer().SetHorizontalOffset(e.HorizontalOffset);

this.Datagrid2.GetVisualContainer().SetHorizontalOffset(e.HorizontalOffset);

}


if (e.VerticalChange > 0 || e.VerticalChange < 0)

{

this.Datagrid1.GetVisualContainer().SetVerticalOffset(e.VerticalOffset);

this.Datagrid2.GetVisualContainer().SetVerticalOffset(e.VerticalOffset);

}

}


//ScrollChanged event of ScrollViewer in Datagrid2

void ScrollOwner2_ScrollChanged(object sender, ScrollChangedEventArgs e)

{

if (e.HorizontalChange > 0 || e.HorizontalChange < 0)

{

this.Datagrid1.GetVisualContainer().SetHorizontalOffset(e.HorizontalOffset);

this.Datagrid2.GetVisualContainer().SetHorizontalOffset(e.HorizontalOffset);

}

if (e.VerticalChange > 0 || e.VerticalChange < 0)

{

this.Datagrid1.GetVisualContainer().SetVerticalOffset(e.VerticalOffset);

this.Datagrid2.GetVisualContainer().SetVerticalOffset(e.VerticalOffset);

}

}


Please let us know in case of any other queries.

Regards,
Muthalagu

Loader.
Live Chat Icon For mobile
Up arrow icon