Have two SfDataGrid scrolled together in Xamarin.Forms

I need to have two SfDataGrid side by side on the same page.  If the user scrolls one vertically, the other one must scroll too.
Is there a way to do it by accessing the intern SfDataGrid ScrollView or any other way ?

Thanks

1 Reply

VR Vigneshkumar Ramasamy Syncfusion Team October 30, 2018 07:29 AM UTC

 
Hi Barry,  
 
Thanks for contacting Syncfusion Support.   
 
Your requirement to scroll the 2nd SfDataGrid, when 1st SfDataGrid is scrolled, can be achieved in sample level by using the below code snippet. 
 
    public partial class MainPage : ContentPage 
    { 
        VisualContainer container; 
        VisualContainer container1; 
 
        public MainPage() 
        { 
            InitializeComponent(); 
            container = dataGrid.GetType().GetProperty("VisualContainer", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(dataGrid) as VisualContainer; 
            container1 = sfGrid.GetType().GetProperty("VisualContainer", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(sfGrid) as VisualContainer; 
        } 
 
        private void DataGrid_GridLoaded(object sender, GridLoadedEventArgs e) 
        { 
            if (Device.RuntimePlatform == TargetPlatform.Android.ToString()) 
            { 
                container.AndroidScrollOwner.Scrolled += AndroidScrollOwner_Scrolled; 
            } 
            else 
            { 
                container.ScrollOwner.Scrolled += ScrollOwner_Scrolled; 
            } 
        } 
 
        private void AndroidScrollOwner_Scrolled(object sender, ScrolledEventArgs e) 
        { 
            container1.AndroidScrollOwner.ScrollToAsync(e.ScrollX, e.ScrollY, true); 
        } 
 
        private void ScrollOwner_Scrolled(object sender, ScrolledEventArgs e) 
        { 
            container1.ScrollOwner.ScrollToAsync(e.ScrollX, e.ScrollY, true); 
        } 
    } 


 
We have prepared the sample as per your requirement, you can download the same from below link.  
 
 
Regards,  
Vigneshkumar R 


Loader.
Up arrow icon