# ScrollToIndex doesn't work when dataprovider has just been updated

I experienced a problem with a datagrid where I tried to use a scrollToIndex.

This was the necessary workflow:

• load a xml from a webservice and place the result in a datagrid
• select an item from the datagrid
• change it in a seperate panel + save
• reload the webservice and replace the content of the datagrid with the new xml
• set the selectedIndex and scrollToIndex to the row which was updated

The selectedIndex worked, the scrollToIndex not.

The answer is simple once you know it: add dg.validateNow() before calling the scrollToIndex !

Example without the validateNow
–> this datagrid gets really messy with the second button clicked!

Example with the validateNow
–> everything ok here!

This is the code:

not working:

click="dgTest.selectedIndex=7; dgTest.scrollToIndex(7);"


working:

click="dgTest.dataProvider=[]; dgTest.dataProvider=employees; dgTest.validateNow(); dgTest.selectedIndex=7; dgTest.scrollToIndex(7);"