How to access data from row in Grid while selecting it so that further it can be used in Text Field below in Adobe Flex (ActionScript)?

82 views Asked by At

I've created a Grid that takes data from an XML file. I need to get the entire row value and display them in the text field below accordingly. I was able to achieve the row index of the selected row but couldn't get the entire row data. I tried using event target and grid selected index

The code for reference is hereby attached.

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
                       xmlns:s="library://ns.adobe.com/flex/spark"
                       xmlns:mx="library://ns.adobe.com/flex/mx"
                       width="1186" height="646" backgroundColor="#FFFFFF"
                      
                       applicationComplete="srv.send()"
                       
                       >
    <s:layout>
        <s:BasicLayout/>
    </s:layout>
        

    <fx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            import mx.controls.Alert;
            import mx.core.mx_internal;
            import mx.events.FlexEvent;
                [Bindable]
            public function initFunc():void
            {
                thisButton.addEventListener("click",clickFunction);
            }
            
            **public function dada(event:Event):void
            {
            Alert.show(myGrid.selectedIndex.toString()+" "+event.target.text);
            naam.text=event.target.text
            
            }**

            protected function button1_creationCompleteHandler(event:FlexEvent):void
            {
                // TODO Auto-generated method stub
                
            }
            
        ]]>
        
        
        
    </fx:Script>
    <fx:Declarations>
        <mx:HTTPService id="srv" url="file:///C:/Users/Chaitanya.Galande/Desktop/first.xml">
        </mx:HTTPService>
    </fx:Declarations>

        
    
    <mx:VBox x="111" y="0" width="981" height="636" backgroundColor="#9CD0E3"
             contentBackgroundColor="#F5F5F5">
        <mx:DataGrid id="myGrid" width="856" click="dada(event)" color="#1B7DA6"
                     dataProvider="{srv.lastResult.Contacts.Contact}" fontSize="16">
            
        </mx:DataGrid>
        
        <mx:TextInput id="naam" text="dabcd"/>
        <mx:TextInput text="ada" id="age"/>
        <mx:TextInput text="ada" id="hobby"/>
        <mx:TextInput text="adasdadas" id="phone"/>
        <s:Button id="thisButton" height="39" label="Refresh" color="#9F41B6"
                  creationComplete="button1_creationCompleteHandler(event)" fontFamily="Courier New"
                  fontSize="20" fontStyle="normal" textDecoration="none" click="clickFunction(event)"/>
        <mx:Image source="a.png" />
    </mx:VBox>
</s:WindowedApplication>

1

There are 1 answers

0
Ali Nabeel On

Use selectedItem instead of selectedIndex That what I use in animate with as3