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

ScrollIntoView with DataPager and Gridview

3 Answers 135 Views
DataPager
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 1
Tim asked on 17 Nov 2010, 01:43 AM
I've been able to programmatically set the SelectedItem in a WPF RadGridView and then call ScrollIntoView to get it to be visible in the grid.  But when I couple that with a RadDataPager it stops working.  I suspect I have to do something like Scroll in the pager, or instead of.  I have an object with a public SelectedItem that I had been passing into the gridview.ScrollIntoView.  Is there something like this I need to do to get at the right page of the DataPager, so my selected item shows up?

3 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 17 Nov 2010, 09:56 AM
Hello Tim,

That is completely impossible.

Once the grid is paged, it can no longer be aware that there are other pages besides the one it is currently showing. In other words, the grid is totally clueless that there is paging going on -- when the user clicks buttons on the pager, the grid "thinks" that someone is changing it entire ItemsSource.

Imagine that our data is 1,2,3,4 and we have a page size of 2. When we are on the first page, the grid thinks that its ItemsSource is the 1,2. When we are in the second page, the grid thinks that its ItemsSource is 3,4. So when the ItemsSource is 3,4 you simply cannot scroll to 2 since this item is not in the ItemsSource. So you can not scroll to an item, which is on another page since this item is not in the ItemsSource of the grid.

I hope this makes sense.

Sincerely yours,
Ross
the Telerik team
See What's New in RadControls for WPF in Q3 2010 on Tuesday, November 16, 2010 11:00 AM - 12:00 PM EST or 10:00 PM - 11:00 PM EST: Register here>>
0
Tim
Top achievements
Rank 1
answered on 17 Nov 2010, 06:29 PM
Obviously I can do this myself, by knowing what item is selected, dividing by the number items per page, then telling the DataPager to go to that page.  I was just hoping that since this seems like quite a common need for developers you might have incorporated such a technique into the $1000 package we just bought. If you have any other ideas please let me know, thanks.
0
Lawrence
Top achievements
Rank 2
Iron
answered on 10 Feb 2015, 02:35 PM
If you have all of the data, you can use this extension method.
public void ScrollIntoView<T>(T dataItem, RadDataPager radDataPager)
{
    var items = (Collection<T>)this.ItemsSource;
    int index = items.IndexOf(dataItem);
    int page = (int)Math.Floor((double)index / radDataPager.PageSize);
 
    radDataPager.MoveToPage(page);
 
    this.SelectedItem = items[index];
    this.ScrollIntoView(this.SelectedItem);
}
Tags
DataPager
Asked by
Tim
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Tim
Top achievements
Rank 1
Lawrence
Top achievements
Rank 2
Iron
Share this question
or