Question

I have an ArrayCollection filled with 'o' objects. This AC should be the dataProvider of a DataGrid. After setting the dp: dgMT.dataProvider=acDataGrid the DataGrid contains only the last item of the arrayCollection. Code:

[Bindable]
        public var acDataGrid:ArrayCollection = new ArrayCollection();
        protected function ddlLanguage_changeHandler(event:IndexChangeEvent):void{

            gcTranslate.headerText=Globals.acLanguages.getItemAt(ddlLanguage.selectedIndex,0).toString();
            Globals.acActValues=convertXmlToArrayCollection(File.applicationDirectory.resolvePath("xmls"+File.separator+Globals.acFileNames.getItemAt(ddlLanguage.selectedIndex,0)));

            Globals.acDataGrid.removeAll();
            var o:DataGridObject = new DataGridObject();
            var i:int=0;
            var angol:Object;
            for each(angol in Globals.acValues){
                o.en=angol.value;
                o.name=angol.name;

                if(i<Globals.acActValues.length && o.name==Globals.acActValues.getItemAt(i,0).name){
                    o.translation=Globals.acActValues.getItemAt(i,0).value;                 

                }
                else{
                    o.translation="";
                    Globals.acActValues.addItemAt("",i);
                }

                acDataGrid.addItemAt(o,i);

                trace("NAME: "+acDataGrid.getItemAt(i,0).name+" VAL:"+acDataGrid.getItemAt(i,0).en+"TRANS: "+acDataGrid.getItemAt(i,0).translation);
// the values are different!
                i++;
            }
            dgMT.dataProvider=acDataGrid;//setting the dataProvider         

        }

How could I reach that the DataGrid's rows are filled with the correct values? Thank you!

Was it helpful?

Solution

You're instantiating o just once, outside of the for loop. Which means your just changing the values of that instance's properties and adding that same instance to the dataprovider over and over. You should instead create a new instance on every iteration.

To fix this, simply move the instantiation of o inside the for loop:

for each(angol in Globals.acValues){
    var o:DataGridObject = new DataGridObject();
    ...
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top