2 Replies Latest reply on Nov 26, 2007 4:37 PM by mike_morearty

    Adding rows to DataGrid

    Zolotoj Level 3
      Any samples of how to add new rows to a DataGrid?

        • 1. Re: Adding rows to DataGrid
          Zolotoj Level 3
          Ok, I have put some code together but it does not work.
          Any idea why?
          • 2. Re: Adding rows to DataGrid
            mike_morearty Level 1
            Here is a complete working sample that works. Your code sample isn't a complete sample, so I'm not quite sure which part caused your problem, but if I had to guess, I would bet the problem is caused by the fact that you did "addItem(Countries)" when you should have done "addItem(Countries.country)". Countries is an XML object whose root tag is <countries>; Countries.country is an E4X expression that resolves to an XMLList of tags, each of whose tagname is <country> (and in this particular case, that list will have just a single entry).

            Anyway, here's my working sample:

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" >
            public var Countries:XML =
            <country continent="Europe" countryName="Ukraine" article="test" />

            <mx:XML id="mydata" xmlns="">
            <country continent="North America" countryName="United States" article="test" />
            <country continent="North America" countryName="Canada" article="test" />
            <mx:DataGrid id="grdAdvGrid" dataProvider="{mydata.country}">
            <mx:DataGridColumn dataField="@continent" headerText="Continent" />
            <mx:DataGridColumn dataField="@countryName" headerText="Country" />
            <mx:Button x="212" y="220" label="Add" click="grdAdvGrid.dataProvider.addItem(Countries.country)"/>