Skip to main content

Microsoft Silverlight

Answered Question ScrollIntoView in DataGrid Dec 2008RSS Feed

(0)

Firehead
Firehead

Member

Member

2 points

5 Posts

ScrollIntoView in DataGrid Dec 2008

 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
ken tucker

All-Star

All-Star

16344 points

2,498 Posts

Re: ScrollIntoView in DataGrid Dec 2008

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:

  1. 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.

 

http://blogs.msdn.com/scmorris/archive/2008/12/19/silverlight-2-datagrid-december-2008-release.aspx

Try making mainlist an ObservableCollection

Firehead
Firehead

Member

Member

2 points

5 Posts

Re: ScrollIntoView in DataGrid Dec 2008

Ken Tucker:
Try making mainlist an ObservableCollection
 

 Are you sure? ObservableCollection doesn't implement ICollectionView.

yifung
yifung

Contributor

Contributor

3315 points

541 Posts

Microsoft
Answered Question

Re: ScrollIntoView in DataGrid Dec 2008

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.

Yifung Lin [MSFT]

mohanbrij
mohanbrij

Member

Member

5 points

6 Posts

Re: ScrollIntoView in DataGrid Dec 2008

try this...it worked for me.
dataGrid.UpdateLayout();
dataGrid.ScrollIntoView(mainList[50], dataGrid.Columns[0]);

Please remember to click “Mark as Answer” on the post that helps you

Best Regards
Brij Mohan
http://www.dotnetglobe.com
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities