Hmm. try this instead.
If ( dg.columns[0] != null ) Dg.columns[0].headerText = "foo"; This checks to see if the grid has a column and adds the header if its there. notice that I said _after_ you set the dataprovider! The only reason that you wouldn't have a column is that your data is malformed or contains a gaseous substance (air). Undefined is a different story. Rick Winscot From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of markgoldin_2000 Sent: Friday, March 21, 2008 12:28 AM To: [email protected] Subject: [flexcoders] Re: Loop thru XML data And I would but trace(dg.columns[0]) // undefined --- In [email protected] <mailto:flexcoders%40yahoogroups.com> , "Rick Winscot" <[EMAIL PROTECTED]> wrote: > > After you set the data provider there isn't any reason that you can't: > > > > dg.columns[0].headerText = "ColumZOR Heading"; > > > > When dataGrid-ing. there will be a few items that you will need to provide > no matter what path you go down (dynamic, mxml, design time, runtime ). > Column headings is one of them - since columns don't know where to pull > headerText from (i.e. a function, field, attribute, etc) by default. > > > > Rick Winscot > > All your e4x are belong to us.. > > > > > > > > From: [email protected] <mailto:flexcoders%40yahoogroups.com> [mailto:[email protected] <mailto:flexcoders%40yahoogroups.com> ] On > Behalf Of markgoldin_2000 > Sent: Thursday, March 20, 2008 12:26 PM > To: [email protected] <mailto:flexcoders%40yahoogroups.com> > Subject: [flexcoders] Re: Loop thru XML data > > > > Very interesting!! > I am assigning data like this: > dg.dataProvider = xmlData.elements("location"); > where xmlData fragment is: > <location>Departure Yard</location> > <location>West Class</location> > <location>East Class</location> > > I see my data in one column but the column does not have a header > text. Also dg.columns.length() shows 0. But I would think it must be > 1. What am I missing here? > Can you provide a sample of an XML that will create columns as well > as populate grids with data in your one linner code? > > Thank a lot. > > --- In [email protected] <mailto:flexcoders%40yahoogroups.com> <mailto:flexcoders% 40yahoogroups.com> , > "Rick Winscot" <rick.winscot@> > wrote: > > > > To Tracy *The Man With Loopage*: > > > > > > > > If you just take the original output from that one liner and send > it to the > > provider of a datagrid with no columns - the data will magically > flow into > > the grid without having to create columns! He might need to tweak > the > > structure of his xml so that the columns look right though. > > > > > > > > BAM! > > > > > > > > Rick Winscot > > > > > > > > > > > > From: [email protected] <mailto:flexcoders%40yahoogroups.com> <mailto:flexcoders% 40yahoogroups.com> > [mailto:[email protected] <mailto:flexcoders%40yahoogroups.com> <mailto:flexcoders% 40yahoogroups.com> ] > On > > Behalf Of Tracy Spratt > > Sent: Monday, March 17, 2008 9:05 PM > > To: [email protected] <mailto:flexcoders%40yahoogroups.com> <mailto:flexcoders% 40yahoogroups.com> > > Subject: RE: [flexcoders] Loop thru XML data > > > > > > > > As I read his post he really does want to loop, so he can use the > iterations > > to build DG columns dynamically. > > > > > > > > It I am correct then take Rick's e4x expression, punk, and do this: > > > > > > > > var xlColumns:XMLList = xml.destinationcodecolumns.elements ("code"); > > > > var xmlColumn:XML; > > > > for (var i:int=0;i<xlColumns.length();i++) { > > > > xmlColumn = xlColumns[i]; > > > > //. do whatever > > > > } > > > > > > > > But now, reading the original post again, maybe this is not what he > wants. > > But I already wrote this response, it so here it is. > > > > > > > > Tracy > > > > _____ > > > > From: [email protected] <mailto:flexcoders%40yahoogroups.com> <mailto:flexcoders% 40yahoogroups.com> > [mailto:[email protected] <mailto:flexcoders%40yahoogroups.com> <mailto:flexcoders% 40yahoogroups.com> ] > On > > Behalf Of Rick Winscot > > Sent: Monday, March 17, 2008 8:38 PM > > To: [email protected] <mailto:flexcoders%40yahoogroups.com> <mailto:flexcoders% 40yahoogroups.com> > > Subject: RE: [flexcoders] Loop thru XML data > > > > > > > > You wanna use e4x? Huh? Huh? Go ahead make my day. > > > > > > > > dg.dataProvider = xml.destinationcodecolumns.elements("code"); > > > > > > > > Rick *no loops required* Winscot > > > > > > > > > > > > > > > > From: [email protected] <mailto:flexcoders%40yahoogroups.com> <mailto:flexcoders% 40yahoogroups.com> > [mailto:[email protected] <mailto:flexcoders%40yahoogroups.com> <mailto:flexcoders% 40yahoogroups.com> ] > On > > Behalf Of markgoldin_2000 > > Sent: Monday, March 17, 2008 6:43 PM > > To: [email protected] <mailto:flexcoders%40yahoogroups.com> <mailto:flexcoders% 40yahoogroups.com> > > Subject: [flexcoders] Loop thru XML data > > > > > > > > I have the following xml fragment: > > <root> > > <destinationcodecolumns> > > <code>3700</code> > > <code>4400</code> > > <code>3400</code> > > <code>3500</code> > > </destinationcodecolumns> > > > > .... > > > > I need to loop thru code element in order to create a grid with > dynamic > > columns. How does the loop might look like? > > > > Thanks for help. > > >
<<image001.jpg>>
<<image002.jpg>>

