4 Replies Latest reply on Dec 4, 2009 6:56 AM by Jerry62712

    How do I take a datagrid row and put in textInput

    Jerry62712 Level 1

      On a search form we have a datagrid that will be populated from a database.  My task is to take the row a user clicks on to populate forms with the data.  Essentially this is taking one row and putting each field into its own textInput control.

       

      Each of the controls are linked to an XML tag:

      <mx:XML id="dmSearch">
      
          <data>
              <SearchResults>
                  <result>
      ...
                  </result>
              </SearchResults>
      
              <SearchCriteria>
      ...
              </SearchCriteria>
      
              <RecProcess>
                  <ADDRESS /> 
                  <AGE /> 
      ...
              </RecProcess>
      
      

      So the "ADDRESS" is bound:

                          <mx:FormItem id="dtAddress"
                              label="Address"
                              y="35" x="5"
                              width="275"
                              horizontalAlign="right">
                              <mx:TextInput id="RECPROVIDERADDRESS"
                                  text="{dmSearch.RecProcess.RECPROVIDERADDRESS}"
                                  change="dmSearch.RecProcess.RECPROVIDERADDRESS=RECPROVIDERADDRESS.text; lcConnector.setDirty();"
                                  width="140"
                                  maxChars="50"/>
                          </mx:FormItem>

       

      I want to pull the data from this grid:

                          <mx:Form id="searchResults"
                              horizontalCenter="0">
                              <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>
                          </mx:Form>

      The datagrid doc at http://livedocs.adobe.com/flex/3/html/help.html?content=dpcontrols_6.html doesn't seem to cover this at all.

        • 1. Re: How do I take a datagrid row and put in textInput
          Flex harUI Adobe Employee

          Bind to dataGrid.selectedItem.

           

          Alex Harui

          Flex SDK Developer

          Adobe Systems Inc.

          Blog: http://blogs.adobe.com/aharui

          • 2. Re: How do I take a datagrid row and put in textInput
            Jerry62712 Level 1

            Thanks for the reply.  Could you expand on that a little?  The input elements are bound to the XML stuff under the subheading.  Can they be bound to something else as well?

            • 3. Re: How do I take a datagrid row and put in textInput
              Gregory Lafrance Level 6

              You should use something like this to bind to the DataGrid selectedItem property:

               

              <mx:TextInput id="RECPROVIDERADDRESS" text="{dgSearchResults.RecProcess.RECPROVIDERADDRESS}"

               

              You may need to play with the e4x a bit.

               

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


              Greg Lafrance
              www.ChikaraDev.com

              Flex Development and Support Services

              • 4. Re: How do I take a datagrid row and put in textInput
                Jerry62712 Level 1

                Hi, Greg.

                 

                Each of the textInput items are bound to an XML item:

                                    <mx:FormItem id="gWorkPhone"
                                        label="Work Phone"
                                        x="5"
                                        width="250"
                                        horizontalAlign="right">
                                        <mx:TextInput id="WORKPHONE"
                                            text="{dmResults.WORKPHONE}"
                                            change="dmResults.WORKPHONE=WORKPHONE.text; lcConnector.setDirty();"
                                            width="115"
                                            maxChars="50"/>
                                    </mx:FormItem>
                (I changed the name in trying to work this out.  I created two XML items (dmSearch and dmResults) which I assume is OK.)

                 

                The item will either contain (through some magic I don't understand yet) the data from the user selected datagrid or blanks for input of new records.  The grid items are filtered based on the search function (resulting in an error):

                            var psrSODC:String = dgSearchResults.selectedItem.colSODC as String;

                           if (psrSODC != null && psrSODC.length > 0)
                            {
                                XMLRecord = dmResults(SODC == psrSODC);
                            }
                There are several of these statements as the user might enter 1 to n criteria.  Is this the way to filter the input grid to one record?  And how does "XMLRecord" know the layout of the file?