Skip to main content
Home Forums Silverlight Programming Silverlight Controls and Silverlight Toolkit ScrollIntoView in DataGrid Dec 2008
4 replies. Latest Post by mohanbrij on June 30, 2009.
(0)
Firehead
Member
2 points
5 Posts
12-22-2008 9:12 AM |
Hi all!
I have such problem: I decided to upgrade DataGrid in my project to December 2008 release. But after I did that method ScrollIntoView stopped working at all. Some code for example:
dataGrid.ItemsSource = mainList;dataGrid.ScrollIntoView(mainList[50], dataGrid.Columns[0]);
There are dataGrid is DataGrid (Dec'08), mainList is List collection with 100 items. I want to scroll DataGrid to the 50th element (row), but in fact DataGrid starts display data from the first item of mainList (ItemSource).
ken tucker
All-Star
16344 points
2,498 Posts
12-22-2008 11:57 AM |
From Scott Morrison's blog
Breaking Changes As a result of these fixes there are several behavioral breaking changes that you should consider before upgrading: The DataGrid’s current cell is now kept in sync with an ICollectionView’s notion of currency. Moving the current position or changing the current item of an ICollectionView will now move the current cell and selected item of a DataGrid, and vice versa. For this to work, the DataGrid’s ItemsSource must be set to a collection that fully implements ICollectionView.
As a result of these fixes there are several behavioral breaking changes that you should consider before upgrading:
Try making mainlist an ObservableCollection
12-23-2008 6:34 AM |
Ken Tucker:Try making mainlist an ObservableCollection
Are you sure? ObservableCollection doesn't implement ICollectionView.
yifung
Contributor
3315 points
541 Posts
12-23-2008 3:27 PM |
The issue here is the rows are no longer created immediately anymore. They are delayed until the layout pass now so things are properly calculated. As a result, there aren't any rows yet when you call ScrollIntoView, and that's why it's not working now. I'm sorry this wasn't included as part of the list of breaking changes.
What you need here is the Loaded event. You would wait until the DataGrid has Loaded and then call ScrollIntoView. However, there's a bug in Silverlight where the Loaded event is raised prematurely so you can't use that as expected. As a substutite, you could BeginInvoke the call to ScrollIntoView once LoadingRow is raised for the row you want.
mohanbrij
5 points
6 Posts
06-30-2009 7:34 AM |
try this...it worked for me. dataGrid.UpdateLayout(); dataGrid.ScrollIntoView(mainList[50], dataGrid.Columns[0]);