This is a migrated thread and some comments may be shown as answers.

[Solved] Programmatically scrolling row to top

1 Answer 212 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Roberto
Top achievements
Rank 1
Roberto asked on 27 Jul 2011, 12:01 AM
Hi,

I have a grid view on a pretty long Silverlight web part and I want to programmatically scroll to an specified item but making this the item at the top. Using the ScrollIntoView I can scroll it to the bottom but not to the top. Any way to do this out of the box?

1 Answer, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 28 Jul 2011, 11:42 AM
Hi Roberto,

 Indeed generally the ScrollIntoView method will scroll so that the item is visible, it will not show it at the very top of the visible area.

What you may do to scroll a specific item to the top is to first scroll outside of the visible area and then scroll to the specific item using ScrollIntoViewAsync method. For example if you would like to scroll to item[5] of the playersGrid, then your code should look like this one:

GridViewScrollViewer scrollViewer = this.playersGrid.ChildrenOfType<GridViewScrollViewer>().FirstOrDefault();
            scrollViewer.ScrollToVerticalOffset(scrollViewer.VerticalOffset + scrollViewer.ViewportHeight);
            this.playersGrid.ScrollIntoViewAsync(playersGrid.Items[5], playersGrid.Columns[0],
            new Action<FrameworkElement>((f) =>
            {
                GridViewRow row = f as GridViewRow;
                if (row != null)
                    row.Cells.Cast<GridViewCell>().First(c => c.Column == playersGrid.Columns[0]).Focus();
            }));
 
Is this what are you looking for?

All the best,
Didie
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
GridView
Asked by
Roberto
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Share this question
or