Question

Let me explain the situation...

dg.selectedItems gives me all the values selected, but if i need one column names value alone then what should i do.

<mx:DataGridColumn dataField="1" headerText="Email" />
Was it helpful?

Solution

dg.selectedItems[itemIndex]["columnName"]

itemIndex = the index of the selected item in the array

note: this is if you have allowMultipleSelection = true... if you are only selected a single item/row use dg.selectedItem. This will return an object of all the columns.

Added full working code example below:

<?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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top