Ah, I see a couple issues: When you add a step, you want to only add the "step" node. In your init function you are calling addChiled but passing the entire "steps" node.
Do you specifically want a "Payments" row to start out with? It should not be necessary. But if so, initialize the DG like this: gridData = new XMLListCollection(gridInitXML.step ); //that expression returns an XMLList with a single step node. In your addStep function do: gridData.addItem(<Step Payments="" Amount="0">); Note, if you want to move the user to the new row and start them editing a cell, use, I believe, editedItemPosition. You probably need to use callLater to invoke that because you need to give the DG time to render the new row before performing actions on it via the UI. Tracy ________________________________ From: [email protected] [mailto:[email protected]] On Behalf Of Tracy Spratt Sent: Monday, December 29, 2008 12:47 PM To: [email protected] Subject: RE: [flexcoders] DataGrid and XMLListCollection - newbie question Looks pretty close. What is not working? Tracy ________________________________ From: [email protected] [mailto:[email protected]] On Behalf Of Pete Appleby Sent: Friday, December 26, 2008 1:51 PM To: [email protected] Subject: [flexcoders] DataGrid and XMLListCollection - newbie question Hi. I am trying to get a very simple datagrid up and going. I need to be able to populate this from an XMLListCollection. This seems very simple, but I am obviously missing the point somewhere in this. It seems that all of the books and online searchs show web services, etc. as source. I need to be able to start at a simpler point. I have tried setting things up both in ActionScript and mxml. The ActionScript is commented out at this point. Either way would be fine. The best would be able to see it work in both ways. The purpose of this snippet is: 1. Initialize the grid with a single row. When the app starts, I have an empty grid. I need to start with a default row in the grid. 2. Allow the user to click the Add Step button to add a new row to the bottom of the grid. 3. Allow the user to click the Clear Steps button to remove all existing rows and then add the default row. 4. Later in the development of this, I will extract the bound data from the grid to create a payment schedule. Here is the code. Thanks! Pete <?xml version="1.0" encoding="utf-8"?> <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml <http://www.adobe.com/2006/mxml> " layout="absolute" applicationComplete="initApp()" > <mx:Script> <![CDATA[ import mx.collections.XMLListCollection; /* [Bindable] public var gridData:XMLListCollection; private const gridInitXML:XML = <Steps> <Step Payments="1" Amount="100" /> </Steps> ; */ private function initApp():void{ // initialize the data grid // gridData = new XMLListCollection( ); // gridData.addItem( gridInitXML ); } private function handleAddStep():void { gridData.addItem(gridInitXML); } private function handleClearSteps():void { gridData.removeAll(); gridData.addItem(gridInitXML); } ]]> </mx:Script> <mx:XMLListCollection id="gridData" source="{Steps}" /> <mx:XMLList id="Steps" xmlns=""> <Step Payments="1" Amount="100" /> </mx:XMLList> <mx:XML id="gridInitXML" > <Steps> <Step Payments="1" Amount="100" /> </Steps> </mx:XML> <mx:Button x="10" y="10" label="Add Step" width="86" id="btnAddStep" click="handleAddStep()" /> <mx:Button x="114" y="10" label="Clear Steps" width="96" id="btnClearSteps" click="handleClearSteps()"/> <mx:DataGrid id="dgSteps" editable="true" enabled="true" dataProvider="{gridData}" x="10" y="38" width="200" height="190" > <mx:columns> <mx:DataGridColumn headerText="Payments" dataField="Payments" width="75" textAlign="right"/> <mx:DataGridColumn headerText="Amount" dataField="Amount" textAlign="right"/> </mx:columns> </mx:DataGrid> </mx:WindowedApplication>

