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

Scroll to horizontal offset in datagrid

How do you do the equivalent of ScrollViewer.ScrollToHorizontalOffset(##) for a data grid?

I have successfully used the .ScrollColumnIntoView(col#) command, but when combined with a frozen first column in snapped view, the datagrid scrolls to the column and cuts off the leftmost portion of the target column, so I need more precision.

Thank you.



3 Replies

PS Prakash Selvaraj Syncfusion Team April 17, 2013 07:03 AM UTC

Hi Gary,

 

We have analysed your query, you can achieve your requirements by getting the ScrollableContentViewer from VisualTreeHelper, and then you can directly use the ScrollToHorizontalOffset method from ScrollableContentViewer object.

Please refer the following code snippet.

Code Snippet [C#]:

void MainPage_Loaded(object sender, RoutedEventArgs e)

{

    scrollViewer = FindDescendant(datagrid, typeof(ScrollableContentViewer)) as ScrollableContentViewer;

    scrollViewer.ScrollToHorizontalOffset(offset);

}

 

DependencyObject FindDescendant(DependencyObject startingFrom, Type typeDescendant)

{

    DependencyObject visual = null;

    var iCount = VisualTreeHelper.GetChildrenCount(startingFrom);

    for (var i = 0; i < iCount; ++i)

    {

        var child = VisualTreeHelper.GetChild(startingFrom, i);

        if (typeDescendant == child.GetType())

        {

            visual = child;

            break;

        }

        visual = FindDescendant(child, typeDescendant);

        if (visual != null)

            break;

    }

    return visual;

}

 

 

 

Please let us know if you need further assistance

 

Regards,

Prakash S.                                                                                     



GP Gary Pansino April 17, 2013 04:22 PM UTC

Works perfectly ... thanks.


PS Prakash Selvaraj Syncfusion Team April 24, 2013 09:12 AM UTC

Hi Gary,

Thank you for your feedback, please let us know if you have any concerns.

Regards,

Prakash S.


Loader.
Live Chat Icon For mobile
Up arrow icon