Referencing Item Renderers from Outside
Item renderers are commonly used in flex applications to extend the behavior and appearance of the list controls. These are quite simple and intuitive to implement, and work very well. I have found however, that in some more complex cases there is a need for interaction between the item renderer, and the component which contains the datagrid.
Getting a reference to the DataGrid component from within an item renderer is quite easy. In this case we use the owner property of the item renderer, rather than the parent property we might expect to use, and this will give us a reference to the DataGrid component.
Working in the other direction (getting a reference to a item renderer instance from the parent of the DataGrid) is slightly more difficult. There is no way to get a reference to the item renderers of a DataGrid from outside of the DataGrid class. The references we want however are held in a protected property called listItems. This property returns a 2D array which contains a reference to the item renderer for each cell in the DataGrid. This means that you can extend the DataGrid class and, using the listItems property, implement the required functionality.
I’ll admit, this is possibly a pretty obscure tip that most people will never come across. I post it here regardless just incase someone comes up against this like I did.