2009-07-14 52 views

回答

4
dg.selectedItems[itemIndex]["columnName"] 

的ItemIndex =所選項目的索引數組

音符:這就是如果你有將allowMultipleSelection =真...如果你只選擇單個項/行使用DG .selectedItem。這將返回所有列的對象。

添加完整的工作代碼下面的例子:

<?xml version="1.0"?> 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" > 
    <mx:Script> 
    <![CDATA[ 
    import mx.events.ListEvent; 
    import mx.events.ItemClickEvent; 
     import mx.collections.*; 

     [Bindable] 
     private var dp:ArrayCollection = new ArrayCollection([ 
     {Artist:'Pavement', Album:'Slanted and Enchanted', Price:11.99}, 
     {Artist:'Pavement', Album:'Brighten the Corners', Price:12.99}, 
     {Artist:'Miley Cyrus', Album:'Break Out', Price:10.99}]); 


     private function clickItemHandler(event:ListEvent):void{ 

      if(myGrid.selectedItem != null){ 
       trace(myGrid.selectedItem["Album"]); 
      } 

     } 

    ]]> 
    </mx:Script> 

    <mx:DataGrid id="myGrid" width="350" height="200" 
     dataProvider="{dp}" itemClick="clickItemHandler(event);" > 
     <mx:columns> 
     <mx:DataGridColumn dataField="Album" /> 
     <mx:DataGridColumn dataField="Price" /> 
     </mx:columns> 
    </mx:DataGrid> 
</mx:Application> 
+0

u能告訴我如何代碼...我的意思是 dg.selectedItems.userlevel 我實際上不是讓你輸入....這裏的userlevel是我的數據字段。你的數據網格中有 – Kevin 2009-07-14 20:10:30