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

Scroll to the SelectedItem

1 Answer 190 Views
GridView
This is a migrated thread and some comments may be shown as answers.
medialog
Top achievements
Rank 2
medialog asked on 16 May 2011, 11:03 AM
Hello I use GridView with MVVM and I want the gridView automaticly scroll to the row selected.
I am binded on SelectedItem:
<telerik:RadGridView
                                        Margin="5"
                                        AutoGenerateColumns="False"
                                        x:Name="_radGridView"
                                        DataLoadMode="Asynchronous"
                                        IsReadOnly="True"
                                        SelectedItem="{Binding SelectedItem,Mode=TwoWay}"
                                        ItemsSource="{Binding Path=Items}"/>

In ViewModel I preselect an item who was at the bottom of the grid. So when I display the gridView we have the row selected but it is not visible I must scoll to see it.

So I want the gridwiew automaticly scroll to to the row selected.

An idea to make that?

1 Answer, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 16 May 2011, 03:59 PM
Hello Jérôme,

When you are changing the selected row programmatic, you need to use ScrollIntoViewAsync method that is explained herehttp://www.telerik.com/help/silverlight/gridview-scroll-item.html. By using it you scroll the selected record into view, wait until that is done, then focus on the selected item. The GridView is scrolled to the right position.

In the same method, you should set the currentCellInfo of the GridView as well(otherwise the current cell will remain the one before the change of the selected item).

For example if your grid is named 'playersGrid' your code could look like this:

private void ButtonSelectItem_Click(object sender, RoutedEventArgs e)
        {
            playersGrid.SelectedItem = playersGrid.Items[10];
            playersGrid.ScrollIntoViewAsync(playersGrid.SelectedItem, r =>
            {
                var row = r as GridViewRow;
  
                if (row != null)
                {
                    row.IsCurrent = true;
                    row.Focus();
                }
 
                playersGrid.CurrentCellInfo = new GridViewCellInfo(playersGrid.SelectedItem, playersGrid.Columns[0]);
            });

I hope that this example is answering your question.

Regards,
Didie
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
medialog
Top achievements
Rank 2
Answers by
Dimitrina
Telerik team
Share this question
or