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

GetVisualContainer returns null when SfDataGrid is not on first tab

Hi,
Please see the attached code.

As the title suggests, sfDataGrid.GetVisualContainer() returns null when the SfDataGrid is not on the first tab.
I need access to the VisualContainer so I can add a handler to the sfDataGrid.GetVisualContainer().ScrollOwner.ScrollChanged event.

It works fine if the SfDataGrid is on the first tab, or more precisely, the tab that is active when the application starts.

Cheers,
James.

Attachment: SFDataGridGetVisualContainer_484da829.zip

1 Reply

JN Jayaleshwari N Syncfusion Team February 13, 2019 07:28 AM UTC

Hi James, 
 
Thanks for contacting Syncfusion Support.  
 
We have analyzed your query ”GetVisualContainer returns null when SfDataGrid is not on first tab” and the provided sample from our side. We regret to let you know that you can get the VisualContainer only when the DataGrid is visible.  
 
However you can resolve this by adding null check before using the GetVisualContainer method. SfDataGrid.Loaded event will again raise when switching to the tab containing the SfDataGrid.  
 
sfDataGrid.Loaded += SfDataGrid_Loaded; 
 
private void SfDataGrid_Loaded(object sender, RoutedEventArgs e) 
{ 
    if (sfDataGrid.GetVisualContainer() != null) 
        sfDataGrid.GetVisualContainer().ScrollOwner.ScrollChanged += ScrollOwner_ScrollChanged; 
} 
 
private void ScrollOwner_ScrollChanged(object sender, ScrollChangedEventArgs e) 
{ 
 
} 
 
We have attached the modified sample for your reference and you can download the same from the following location 
 
Please let us know if you would require further assistance. 
 
Regards, 
Jayaleshwari N 


Loader.
Live Chat Icon For mobile
Up arrow icon