Friday, January 19, 2007

Flex Run-Time Error with itemRenderers

Learning to use Flex 2 has been very rewarding. I have had a problem using the DataGrid control with ItemRenderers that I have not been able to resolve. I was able to reproduce the error in a small example. When adding and removing itemRenderers to a datagrid column at run-time I get a RTE. This alone does not seem to cause the RTE but I also set the datagrids dataProvider again which causes the error. You will need the Flash Player Debug version to actually see the error.You can view the example application at . The actual source can by found at App.mxml and LinkRenderer.mxml .

I thought I had a valid workaround when I stopped adding and removing the itemRenderer at Run-Time and just applied it to every column but I am still getting the error sometimes. My small example show the exact error I am getting so if anybody has any ideas please leave me a comment. The problem with learning new technologies is that you can never be sure if it is the technology or the programmer causing the problem. :)


Ted Patrick said...

By default the grid column has a ItemRenderer, so setting this to null will be problematic.

I think this is more a confusion about ItemRenderers in general. The datagrid instanciates a number of ItemRenderers for each row visible in the dataGrid. Data is then 'set value' into these itemRenderer instances.

When you set the ItemRenderer to null and scroll, the 'set value' calls are called on a null ItemRenderer and thus the error.

By default there is an ItemRenderer set that denotes the standard display of the DataGrid. In this case setting it to null actually removes the default value which rightly throws an error.

In a nutshell, do not set the itemRenderer to null.

If you want to presever the default ItemRenderer, save the value before setting it to a custom ItemRenderer and return it to the default value vs setting it to null.

Hope this helps!

Ted :)

Dana said...

This one has been killing me all day long. I finally think I hit something that might fix this. After you add the columns, include a line that does the following:


Nuno said...


I'm having the same issue, but only when switching between other applications.(Alt-Tab). Doing validateDisplayList() isn't the same as doing "mydatagrid.invalidateList();" ?
I've done that and I'm still having the same issue. I really need some help.

OmPrakash Muppirala said...


I recently had similar problems with the DataGrid. After days of breaking my head over this issue, I found a solution where I create the datagrid in ActionScript and not in MXML.

Here is your application re-written. Hope this helps.
I was going to blog about this myself. I thought I would post here first :-)

Here is the modified source code.
Right-click > View Source will give you the modified source code...