tags:

views:

879

answers:

1

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" />
+2  A: 
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>
Shua
can u tell me how to code it... i meandg.selectedItems.userlevel I am not getting your input actually.... userlevel here is my data field.
in your datagrid, are you able to select more than 1 row?if so you need to use dg.selectedItems[selectedRowIndex]["dataField"]but if you are only selecting 1 row use:dg.selectedItem["dataField"]
Shua
myGrid.selectedItem[selectedRowIndex]["Album"]What is that value actually