Using the code below I am able to create an array collection and set 
it as the provider of a datagrid (the resort the columns to match 
the way I want them to display). 

Now I have two issues I need to solve if anyone is able to help: 

1) I have of defined static arrays (mynewArray1 - 3) to add to the 
array collection and I need these to be dynamic (mynewArray[0] - n)

2) When I use myArrayCol.addItem({Name:...) I need to build this 
dynamically since the field names will be dynamic. I'd like to use 
the mycolNames array instead. As an example myArrayCol.addItem
({mycolNames[0]:mynewArray[n][z]}

Here is the code:

___________________________________________________
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"; 
layout="absolute" creationComplete="initArray();">

<mx:Script>
 <![CDATA[
 import mx.controls.dataGridClasses.DataGridColumn;
 import mx.controls.DataGrid;
 import mx.collections.ArrayCollection;
 import mx.controls.Alert;
                        
 [Bindable] public var myArrayCol:ArrayCollection = new 
ArrayCollection();
                
public function initArray():void {
 var mycolNames:Array = ["Name", "Count", "TFBool"];
 var mynewArray1:Array = ["Fred", "Ed", "Jack"];
 var mynewArray2:Array = [1, 2, 3];
 var mynewArray3:Array = [false, true, false];

for (var z:int = 0; z<3; z++) {
 myArrayCol.addItem({Name:mynewArray1[z], Count:mynewArray2[z], 
TFBool:mynewArray3[z]});
}
 
myDG.dataProvider = myArrayCol;
                                
for (var y:int = 0; y < myDG.columns.length; y++) {
 myDG.columns[y].dataField = mycolNames[y];
}
                                
}
 ]]>
</mx:Script>

 <mx:DataGrid id="myDG" x="10" y="10" width="599" height="269"/>
        
</mx:Application>
___________________________________________________

I hope I'm being clear... I need to add an unknown number of columns 
to the ArrayCollection so I can't manually define it in the mxml. 
I'll be looping through a set of user choices and building the array 
collection based on those choices.

Please help!

Reply via email to