Referencing Item Renderers from Outside

Posted on September 26, 2007 by Tony Fendall.
Categories: Adobe, Flex.

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

Comment on September 27th, 2007.

You can always loop over the DataGrid’s children until you find it…

Comment on September 27th, 2007.

If you loop the children of the default datagrid you find it has three direct children:
- A HaloBorder
- A mask, and
- A ListBaseContentHolder

One would assume that the references to the item renderers are held inside the ListBaseContentHolder, but this is an undocumented class, so without tracing through the flex source code I don’t know anything about it. Creating a one line method in the datagrid class to return the array of item renderers is a much easier option :)

Ray
Comment on November 18th, 2007.

Could you provide the example of how you get the reference of itemrenderer within a datagrid?

Comment on September 26th, 2008.

This might be a solution, though I’m still working through it to figure out what the author is doing: http://danonflex.com/print.php?type=A&item_id=5

Audhut
Comment on March 12th, 2009.

i have aproblem using radiobutton in datagrid, when i selct the first radiobutton and then the second one the underlying value of the first radio button is still set to true whereas it should be false

Mudassar
Comment on July 22nd, 2009.

Hi,
Has anyone found a way of getting a reference to a item renderer instance from the DataGrid.
Any help on this is highly appreciated.
Thanks,

Gireesh
Comment on August 27th, 2009.

Hi, Do you know how I can get these details on Flex 2, I dont find ‘itemList’ in ‘ListBaseContentHolder’ for Flex2 SDK