I'm pretty sure that lazy rendering feature re-uses your item renderers as soon as the roll off the screen (to optimize performance). So maybe you only need to do whatever you're doing to the visible ones and it will remain 'done' to all renderer instances?
Are you sure you need to access the ACTUAL visible rows themselves and not the items in your dataProvider that back them? If accessing your backing data is okay, maybe you should iterate through your dataProvider instead.
I made this little application that scrolls to and highlights a row with a function called gotoGridItem(index)
. I scroll to the item before trying to set the selectedIndex--maybe that was what gave you the crash?
Here's my code:
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<mx:AdvancedDataGrid id="theGrid" dataProvider="{rowDataItems}" x="50" y="50"/>
<s:NumericStepper id="rowIndSpr" minimum="0" maximum="{theGrid.dataProvider.length-1}" value="{8}"/>
<s:Button click="gotoGridItem(int(rowIndSpr.value))" label="Go" y="20" />
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[bindable] public var rowDataItems:ArrayCollection = new ArrayCollection([
//...lots of data items for rows ...
]);
public function gotoGridItem(index:uint):void{
theGrid.scrollToIndex(index);
theGrid.selectedIndex = index;
theGrid.validateNow();
}
]]>
</fx:Script>
</s:Application>