1 Reply Latest reply on Dec 5, 2009 10:09 PM by Gregory Lafrance

    How do I get data from a datagrid?

    Jerry62712 Level 1

      We have populated a data grid and now want to extract data from one of the records, but we can't seem to see it.

       

       

       

      <mx:FormItem id="lblSearchResults"

      label="

      Search Results" indicatorGap="0">

       

       

      <mx:DataGrid id="dgSearchResults"

      click="dataGridClicked()"

      >

       

       

      <mx:columns>

       

       

      <mx:DataGridColumn id="colSODC"

      dataField="

      {dmSearch.SearchResults.SODC}"

      headerText="

      SODC"

      headerWordWrap="

      false" />

       

       

      <mx:DataGridColumn id="colLastName"

      dataField="

      {dmSearch.SearchResults.LASTNAME}"

      headerText="

      Last Name"

      headerWordWrap="

      false" />

       

      <mx:DataGridColumn id="colFirstName"

      dataField="

      {dmSearch.SearchResults.FIRSTNAME}"

      headerText="

      First Name"

      headerWordWrap="

      false" />

       

      <mx:DataGridColumn id="colMHDDID"

      dataField="

      {dmSearch.SearchResults.MHDDID}"

      headerText="

      MHDDID"

      wordWrap="

      false" />

       

      <mx:DataGridColumn id="colRIN"

      dataField="

      {dmSearch.SearchResults.RIN}"

      headerText="

      RIN"

      wordWrap="

      false" />

       

      <mx:DataGridColumn id="colSSN"

      dataField="

      {dmSearch.SearchResults.SSN}"

      headerText="

      SSN"

      wordWrap="

      false" />

       

      </mx:columns>

       

      </mx:DataGrid>

       

      </mx:FormItem>

       

      How do I reference say SSN?

        • 1. Re: How do I get data from a datagrid?
          Gregory Lafrance Level 6

          The way you are populating the DataGrid, not using the dataProvider property, is a little foreign to me, but this code works:

           

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"> 
            <mx:Script>
              <![CDATA[
                private function dataGridClicked(evt:MouseEvent):void{
                  txt.text = evt.currentTarget.selectedItem.SSN;
                }
              ]]>
            </mx:Script>
            <mx:TextInput id="txt"/>
            <mx:Form>
              <mx:FormItem id="lblSearchResults" label="Search Results" indicatorGap="0">
                <mx:DataGrid id="dgSearchResults" click="dataGridClicked(event)" dataProvider="{dataXML..SearchResults}">
                  <mx:columns>
                    <mx:DataGridColumn id="colSODC" dataField="SODC" headerText="SODC" headerWordWrap="false" />
                    <mx:DataGridColumn id="colLastName" dataField="LASTNAME" headerText="Last Name" headerWordWrap="false" />
                    <mx:DataGridColumn id="colFirstName" dataField="FIRSTNAME" headerText="First Name" headerWordWrap="false" />
                    <mx:DataGridColumn id="colMHDDID" dataField="MHDDID" headerText="MHDDID" wordWrap="false" />
                    <mx:DataGridColumn id="colRIN" dataField="RIN" headerText="RIN" wordWrap="false" />
                    <mx:DataGridColumn id="colSSN" dataField="SSN" headerText="SSN" wordWrap="false" />
                  </mx:columns>
                </mx:DataGrid> 
              </mx:FormItem>
            </mx:Form>
            <mx:XML id="dataXML" xmlns="">
              <root>
                <SearchResults>
                  <SODC>test1</SODC>
                  <LASTNAME>Carson</LASTNAME>
                  <FIRSTNAME>Bob</FIRSTNAME>
                  <MHDDID>string1</MHDDID>
                  <RIN>test string1</RIN>
                  <SSN>111-11-1111</SSN>
                </SearchResults>
                <SearchResults>
                  <SODC>test2</SODC>
                  <LASTNAME>Whitney</LASTNAME>
                  <FIRSTNAME>Susan</FIRSTNAME>
                  <MHDDID>string2</MHDDID>
                  <RIN>test string2</RIN>
                  <SSN>222-22-2222</SSN>
                </SearchResults>
                <SearchResults>
                  <SODC>test3</SODC>
                  <LASTNAME>Travers</LASTNAME>
                  <FIRSTNAME>Cindy</FIRSTNAME>
                  <MHDDID>string3</MHDDID>
                  <RIN>test string3</RIN>
                  <SSN>333-33-3333</SSN>
                </SearchResults>
              </root>
            </mx:XML>
          </mx:Application>
          
          


          If this post answers your question or helps, please mark it as such.


          Greg Lafrance
          www.ChikaraDev.com

          Flex Development and Support Services