By default, checkbox assumes the data[dataField] is a Boolean and will reflect that value. If you want anything else, you'll need to bake a subclass upfront with the flexibility to do what you want. ItemRenderers are classes and you can't define classes at runtime, you can only tweak properties and styles.
Alex Harui Flex SDK Developer Adobe Systems Inc.<http://www.adobe.com/> Blog: http://blogs.adobe.com/aharui From: [email protected] [mailto:[email protected]] On Behalf Of Penny Laus Sent: Thursday, April 02, 2009 12:52 AM To: [email protected] Subject: [flexcoders] Defining item renderers for a DataGrid using ActionScript I'm trying to create item renderers for DataGrid columns dynamically at runtime and am having a hard time sorting out how to define and attach item renderers. To make sure I've got the mecahnics right first, all I'm trying for now is to make a non-editable column display as a checkbox. My column definitions are stored in an XML file - the snipped below shows how I'm reading the definitions and creating the DataGrid's columns: for each (var columnDefinition:XML in columnDefinitionsXmlList) { var newColumn:DataGridColumn = new DataGridColumn; newColumn.headerText = columnDefinition.col_title; newColumn.dataField = columnDefinition.col_data; newColumn.width = Number(columnDefinition.col_width); if (columnDefinition.col_type == "boolean") { // newColumn.itemRenderer = new ClassFactory(mx.controls.CheckBox); var cb:ClassFactory = new ClassFactory(mx.controls.CheckBox); newColumn.itemRenderer = cb; } columnDefinitions.push(newColumn); } The code shown above does make the column display as a checkbox - but there's no code to turn the checkbox on/off depending on the current cell's value. In the example above, the variable cb is the checkbox that is then associated with the column. What I don't see in FlexBuilder's hinting system is any property of cb that lets me set the condition that controls if the checkbox is on or off - or any of the other properties normally used for an item renderer defined through MXML. Am I missing something obvious or am I going about this in the wrong way? Links to any relevant examples appreciated - I've looked at a lot of examples, but have yet to find one that shows defining an item renderer in quite this way. I'm happy to create a class or component for CheckBox (or whatever else) so long as I'll then be able to set the condition which controls on/off. Thanks for any help.

