Here is an example that uses information in the xml itself to dynamically crate the columns.
http://www.cflex.net/showfiledetails.cfm?ChannelID=1&Object=File&objectI D=552 Tracy ________________________________ From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Alex Harui Sent: Saturday, March 10, 2007 1:03 PM To: [email protected] Subject: RE: [flexcoders] Re: newbie dataGrid question . I can't think of anything better, but I'll guess that by the time you hit production you'll want to define the columns yourself so the headers for price aren't in lower case, and you guarantee a particular order for the columns.. You'll need to think about how you'll figure that out. Maybe the column data can be defined on the server and just shipped over and converted. Then you'll end up with different logic. -Alex ________________________________ From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of iilsley Sent: Friday, March 09, 2007 10:31 PM To: [email protected] Subject: [flexcoders] Re: newbie dataGrid question . This is what I currently have .. is there a better way ?? <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init();"> <mx:Script> <![CDATA[ import mx.controls.Alert; import mx.collections.ArrayCollection; [Bindable] public var dp:ArrayCollection = new ArrayCollection( [{type: 'Pen', price: '10' , label: "Stock Name" } ,{type: 'Sock' , price: '20' , label: "Stock Name" } ! ; ]); private function redraw():void { for ( var a:String in myGrid.columns ) { if (myGrid.columns[a].dataField == "type") { myGrid.columns[a].headerText = dp.source[0]["label"]; continue; &nb! sp; } &nb! sp; &nbs p; if (myGrid.columns[a].dataField == "label") { myGrid.columns[a].visible = false; } } } ]]> </mx:Script> <mx:DataGrid creationComplete="redraw()" id="myGrid" dataProvider="{dp}"/> </mx:Application>

