I ran into similar issues with a DataGrid and multiple element handlers and reusing element rendering when scrolling. To access the means of representing the DataGrid elements, I expanded the DataGrid. My first thought was to use ToIndex () indices, followed by indexToItemRenderer (). Unfortunately, these methods did not do what I expected, so I added the indexItemRenderer () method:
package com.whatever.controls {
import mx.controls.DataGrid; import mx.controls.listClasses.IListItemRenderer; public class CustomDataGrid extends DataGrid { public function CustomDataGrid() { super(); } public function indicesToItemRenderer(rowIndex:int, colIndex:int):IListItemRenderer { var firstItemIndex:int = verticalScrollPosition - offscreenExtraRowsTop; if (rowIndex < firstItemIndex || rowIndex >= firstItemIndex + listItems.length ) { return null; } return listItems[rowIndex - firstItemIndex][colIndex]; } }
To eliminate the means of reusing items while scrolling, see this article:
http://www.adobe.com/devnet/flex/articles/itemrenderers_pt1.html
It comes down to redefining the means of data collection and storing properties in the data. For example, I had one column using the CheckBox itemRenderer element and another column using the ComboBox. For both, I listen to the change event and save the selected ones, selectedIndex, etc. Each time you change the properties and redefine the dataset to set these properties:
override public function set data(value:Object):void { if (value != null) { super.data = value; if (data.hasOwnProperty('selected') && data.selected) { selected = data.selected; } else { selected = false; } } }
Mark tomsu
source share