I finally got something to work (not the best way I'm sure)...now I have to assign an ID number to each dataGrid column name within the array some how. You'll see in the application that when you click on the List entries the dataGrid swaps its colmuns depending on which list name you click on. My goal at this point is to make it so that the user can rearrange (drag and drop) the names that are displayed in the List component and the dataGrid's column names will re-arrange accordingly. Any ideas?
Code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]private var arrayOfString:Array;
[Bindable]private var nIDOne:Number = 0;
[Bindable]private var nIDTwo:Number = 1;
private var arrayOfObject:Array;
[Bindable]
public var DGArray:ArrayCollection = new ArrayCollection([
{Artist:'Jack', Price:'Lots'},
{Artist:'Jill', Price:'None'}
]);
private function init():void {
arrayOfString = ["Artist", "Price"];
myGrid.dataProvider = DGArray;
myGrid.validateNow();
}
private function swapColumns():void {
if(tReturn.selectedItem == "Artist"){
nIDOne = 0;
nIDTwo = 1;
}else if(tReturn.selectedItem == "Price"){
nIDOne = 1;
nIDTwo = 0;
}
init();
}
]]>
</mx:Script>
<mx:DataGrid id="myGrid" initialize="init();">
<mx:columns>
<mx:DataGridColumn dataField="{arrayOfString[nIDOne]}" />
<mx:DataGridColumn dataField="{arrayOfString[nIDTwo]}" />
</mx:columns>
</mx:DataGrid>
<!--<mx:Button label="Swap Columns" click="swapColumns()" />-->
<mx:List
id="tReturn"
dataProvider ="{arrayOfString}"
allowMultipleSelection="true"
labelField="dataField"
dragEnabled="true"
dropEnabled="true"
dragMoveEnabled="true"
click="swapColumns()"
/>
<mx:Label text="Selected (index values): {tReturn.selectedIndex} "/>
<!--<mx:Button label="Swap Columns" click="swapColumns()"/>-->
</mx:Application>
Any input or help is extremely welcome and will be much appreciated!
Thanks!