在List中选中一个就会显示相应的 DataGrid 的列 动态显示/隐藏 DataGrid 的列_html<?xml version="1.0" encoding="utf-8"?>

动态显示/隐藏 DataGrid 的列_html<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="horizontal" horizontalAlign="left"

动态显示/隐藏 DataGrid 的列_html    creationComplete="initApp()">

动态显示/隐藏 DataGrid 的列_html<mx:Script><![CDATA[

动态显示/隐藏 DataGrid 的列_html  import mx.controls.dataGridClasses.DataGridColumn;

动态显示/隐藏 DataGrid 的列_html  //import mx.controls.DataGrid;

动态显示/隐藏 DataGrid 的列_html  import mx.collections.XMLListCollection;

动态显示/隐藏 DataGrid 的列_html  

动态显示/隐藏 DataGrid 的列_html  [Bindable]

动态显示/隐藏 DataGrid 的列_htmlprivate var _xlcCatalog:XMLListCollection;    //the dataProvider for the DG

动态显示/隐藏 DataGrid 的列_html

动态显示/隐藏 DataGrid 的列_html//run by creationComplete

动态显示/隐藏 DataGrid 的列_htmlpublic function initApp():void

动态显示/隐藏 DataGrid 的列_html{

动态显示/隐藏 DataGrid 的列_html    _xlcCatalog = new XMLListCollection(xmlCatalog.product);      //wrap the XML product nodes in an XMLListCollection

动态显示/隐藏 DataGrid 的列_html    lstColumns.selectedItems = new Array(dgHideShow.columns[0]);  //set the column list dataProvider to the DataGridColumns

动态显示/隐藏 DataGrid 的列_html}//initApp

动态显示/隐藏 DataGrid 的列_html

动态显示/隐藏 DataGrid 的列_htmlprivate function hideShowColumns():void  {

动态显示/隐藏 DataGrid 的列_html   var aColumns:Array = dgHideShow.columns;

动态显示/隐藏 DataGrid 的列_html   var aSelectedColumns:Array = lstColumns.selectedItems;

动态显示/隐藏 DataGrid 的列_html   var dgc:DataGridColumn;

动态显示/隐藏 DataGrid 的列_html   var sDataField:String;

动态显示/隐藏 DataGrid 的列_html   var sDataFieldCur:String;

动态显示/隐藏 DataGrid 的列_html   var bFound:Boolean

动态显示/隐藏 DataGrid 的列_html   for (var i:int=0;i<aColumns.length;i++)  {

动态显示/隐藏 DataGrid 的列_html     bFound = false

动态显示/隐藏 DataGrid 的列_html     dgc = aColumns[i];

动态显示/隐藏 DataGrid 的列_html     sDataField = dgc.dataField;

动态显示/隐藏 DataGrid 的列_html     for (var j:int=0;j<aSelectedColumns.length;j++)  {

动态显示/隐藏 DataGrid 的列_html       sDataFieldCur = aSelectedColumns[j].dataField;

动态显示/隐藏 DataGrid 的列_html       if (sDataFieldCur == sDataField)  {

动态显示/隐藏 DataGrid 的列_html         bFound = true;

动态显示/隐藏 DataGrid 的列_html         break;

动态显示/隐藏 DataGrid 的列_html       }

动态显示/隐藏 DataGrid 的列_html     }//for (var j:

动态显示/隐藏 DataGrid 的列_html     if (bFound) {

动态显示/隐藏 DataGrid 的列_html       dgc.visible = true;

动态显示/隐藏 DataGrid 的列_html     }  

动态显示/隐藏 DataGrid 的列_html     else  {

动态显示/隐藏 DataGrid 的列_html       dgc.visible = false;

动态显示/隐藏 DataGrid 的列_html     }     

动态显示/隐藏 DataGrid 的列_html   }// for (var i:

动态显示/隐藏 DataGrid 的列_html}//

动态显示/隐藏 DataGrid 的列_html

动态显示/隐藏 DataGrid 的列_html]]></mx:Script>   

动态显示/隐藏 DataGrid 的列_html  <mx:VBox>

动态显示/隐藏 DataGrid 的列_html    <mx:Label text="Multi-Select" />

动态显示/隐藏 DataGrid 的列_html    <mx:Label text="Columns" />

动态显示/隐藏 DataGrid 的列_html    <mx:List id="lstColumns" dataProvider="{dgHideShow.columns}" 

动态显示/隐藏 DataGrid 的列_html        labelField="dataField" 

动态显示/隐藏 DataGrid 的列_html        allowMultipleSelection="true"

动态显示/隐藏 DataGrid 的列_html        click="hideShowColumns()"  />    

动态显示/隐藏 DataGrid 的列_html  </mx:VBox>

动态显示/隐藏 DataGrid 的列_html

动态显示/隐藏 DataGrid 的列_html  <mx:DataGrid id="dgHideShow" dataProvider="{_xlcCatalog}" rowCount="6" >

动态显示/隐藏 DataGrid 的列_html    <mx:columns>

动态显示/隐藏 DataGrid 的列_html      <mx:Array>

动态显示/隐藏 DataGrid 的列_html        <mx:DataGridColumn headerText="Product" dataField="name" visible="true" />

动态显示/隐藏 DataGrid 的列_html        <mx:DataGridColumn headerText="Description" dataField="description" visible="false" />

动态显示/隐藏 DataGrid 的列_html        <mx:DataGridColumn headerText="Price" dataField="price" visible="false" />

动态显示/隐藏 DataGrid 的列_html        <mx:DataGridColumn headerText="Series" dataField="series" visible="false" />

动态显示/隐藏 DataGrid 的列_html        <mx:DataGridColumn headerText="Tri-Band" dataField="triband" visible="false" />

动态显示/隐藏 DataGrid 的列_html        <mx:DataGridColumn headerText="Camera" dataField="camera" visible="false" />

动态显示/隐藏 DataGrid 的列_html       </mx:Array>

动态显示/隐藏 DataGrid 的列_html    </mx:columns>    

动态显示/隐藏 DataGrid 的列_html  </mx:DataGrid>

动态显示/隐藏 DataGrid 的列_html

动态显示/隐藏 DataGrid 的列_html  <mx:XML id="xmlCatalog">

动态显示/隐藏 DataGrid 的列_html    <catalog>

动态显示/隐藏 DataGrid 的列_html      <product productId="1">

动态显示/隐藏 DataGrid 的列_html        <name>Nokia 6010</name>

动态显示/隐藏 DataGrid 的列_html        <description>Easy to use without sacrificing style, the Nokia 6010 phone offers functional voice communication supported by text messaging, multimedia messaging, mobile internet, games and more</description>

动态显示/隐藏 DataGrid 的列_html        <price>99.99</price>

动态显示/隐藏 DataGrid 的列_html        <image>assets/pic/Nokia_6010.gif</image>

动态显示/隐藏 DataGrid 的列_html        <series>6000</series>

动态显示/隐藏 DataGrid 的列_html        <triband>false</triband>

动态显示/隐藏 DataGrid 的列_html        <camera>false</camera>

动态显示/隐藏 DataGrid 的列_html        <video>false</video>

动态显示/隐藏 DataGrid 的列_html        <highlight1>MMS</highlight1>

动态显示/隐藏 DataGrid 的列_html      <highlight2>Large color display</highlight2>

动态显示/隐藏 DataGrid 的列_html      </product>

动态显示/隐藏 DataGrid 的列_html      <product productId="2">

动态显示/隐藏 DataGrid 的列_html        <name>Nokia 3100 Blue</name>

动态显示/隐藏 DataGrid 的列_html        <description>Light up the night with a glow-in-the-dark cover - when it's charged with light you can easily find your phone in the dark. When you get a call, the Nokia 3100 phone flashes in tune with your ringing tone. And when you snap on a Nokia Xpress-on™ gaming cover*, you'll get luminescent light effects in time to the gaming action.</description>

动态显示/隐藏 DataGrid 的列_html        <price>139</price>

动态显示/隐藏 DataGrid 的列_html        <image>assets/pic/Nokia_3100_blue.gif</image>

动态显示/隐藏 DataGrid 的列_html        <series>3000</series>

动态显示/隐藏 DataGrid 的列_html        <triband>true</triband>

动态显示/隐藏 DataGrid 的列_html        <camera>false</camera>

动态显示/隐藏 DataGrid 的列_html        <video>false</video>

动态显示/隐藏 DataGrid 的列_html        <highlight1>Glow-in-the-dark</highlight1>

动态显示/隐藏 DataGrid 的列_html      <highlight2>Flashing lights</highlight2>

动态显示/隐藏 DataGrid 的列_html      </product>

动态显示/隐藏 DataGrid 的列_html      <product productId="3">

动态显示/隐藏 DataGrid 的列_html        <name>Nokia 3100 Pink</name>

动态显示/隐藏 DataGrid 的列_html        <description>Light up the night with a glow-in-the-dark cover - when it's charged with light you can easily find your phone in the dark. When you get a call, the Nokia 3100 phone flashes in tune with your ringing tone. And when you snap on a Nokia Xpress-on™ gaming cover*, you'll get luminescent light effects in time to the gaming action.</description>

动态显示/隐藏 DataGrid 的列_html        <price>139</price>

动态显示/隐藏 DataGrid 的列_html        <image>assets/pic/Nokia_3100_pink.gif</image>

动态显示/隐藏 DataGrid 的列_html        <series>3000</series>

动态显示/隐藏 DataGrid 的列_html        <triband>true</triband>

动态显示/隐藏 DataGrid 的列_html        <camera>false</camera>

动态显示/隐藏 DataGrid 的列_html        <video>false</video>

动态显示/隐藏 DataGrid 的列_html        <highlight1>Glow-in-the-dark</highlight1>

动态显示/隐藏 DataGrid 的列_html      <highlight2>Flashing lights</highlight2>

动态显示/隐藏 DataGrid 的列_html      </product>

动态显示/隐藏 DataGrid 的列_html      <product productId="4">

动态显示/隐藏 DataGrid 的列_html        <name>Nokia 3120</name>

动态显示/隐藏 DataGrid 的列_html        <description>Designed for both business and pleasure, the elegant Nokia 3120 phone offers a pleasing mix of features. Enclosed within its chic, compact body, you will discover the benefits of tri-band compatibility, a color screen, MMS, XHTML browsing, cheerful screensavers, and much more.</description>

动态显示/隐藏 DataGrid 的列_html        <price>159.99</price>

动态显示/隐藏 DataGrid 的列_html        <image>assets/pic/Nokia_3120.gif</image>

动态显示/隐藏 DataGrid 的列_html        <series>3000</series>

动态显示/隐藏 DataGrid 的列_html        <triband>true</triband>

动态显示/隐藏 DataGrid 的列_html        <camera>false</camera>

动态显示/隐藏 DataGrid 的列_html        <video>false</video>

动态显示/隐藏 DataGrid 的列_html        <highlight1>Multimedia messaging</highlight1>

动态显示/隐藏 DataGrid 的列_html      <highlight2>Animated screensavers</highlight2>

动态显示/隐藏 DataGrid 的列_html      </product>

动态显示/隐藏 DataGrid 的列_html      <product productId="5">

动态显示/隐藏 DataGrid 的列_html        <name>Nokia 3220</name>

动态显示/隐藏 DataGrid 的列_html        <description>The Nokia 3220 phone is a fresh new cut on some familiar ideas - animate your MMS messages with cute characters, see the music with lights that flash in time with your ringing tone, download wallpapers and screensavers with matching color schemes for the interface.</description>

动态显示/隐藏 DataGrid 的列_html        <price>159.99</price>

动态显示/隐藏 DataGrid 的列_html        <image>assets/pic/Nokia_3220.gif</image>

动态显示/隐藏 DataGrid 的列_html        <series>3000</series>

动态显示/隐藏 DataGrid 的列_html        <triband>false</triband>

动态显示/隐藏 DataGrid 的列_html        <camera>true</camera>

动态显示/隐藏 DataGrid 的列_html        <video>false</video>

动态显示/隐藏 DataGrid 的列_html        <highlight1>MIDI tones</highlight1>

动态显示/隐藏 DataGrid 的列_html      <highlight2>Cut-out covers</highlight2>

动态显示/隐藏 DataGrid 的列_html      </product>

动态显示/隐藏 DataGrid 的列_html    </catalog>

动态显示/隐藏 DataGrid 的列_html  </mx:XML>

动态显示/隐藏 DataGrid 的列_html</mx:Application>

动态显示/隐藏 DataGrid 的列_html