4 Replies Latest reply on Oct 8, 2010 2:12 PM by majester8425

    How can I bind an inline combobox component to an array collection ?

    majester8425 Level 1

      I have the following component in a table and it works fine, but I need to populate it from a database and an array collection

       

      <fx:Component id="inlineEditor">
      <mx:ComboBox>
        <mx:dataProvider>
         <fx:String>Bob Marley</fx:String>
         <fx:String>Frank Sinartra</fx:String>
         <fx:String>Pink</fx:String>
         <fx:String>Blue</fx:String>
         <fx:String>Yellow</fx:String>
        </mx:dataProvider>
      </mx:ComboBox>
      </fx:Component>

       

      if I try and chnage it to

       

      <fx:Component id="inlineEditor">
      <mx:ComboBox dataprovider={theDataAc}>
      </mx:ComboBox>
      </fx:Component>

       

      I get an error 1120: Access of undefined property theDataAc, which is clearly defined in the script declaration

       

       

       

        • 1. Re: How can I bind an inline combobox component to an array collection ?
          ssardar

          I'm not seeing where {theDataAC} is defined in what you posted here.

           

          But if you are getting this from a DB in the future, it's fairly simple:

           

          Just declare the ArrayCollection in your script like so:

           

          [Bindable]

           

          private var theDataAC:ListCollectionView = new ArrayCollection();

           

           

          and when you handle the result form your DB call, you should have something like this:

           

           

           

           

          private function handleDBResult(e:ResultEvent):void

          {

             theDataAC = e.result

           

          as ListCollectionView;

           

          }

           

           

           

          All my DB calls are WebService calls so you may have to tweak the handling function a bit, but the process is pretty much the same.

           

           

           

          For combobox I believe as long as it is an ArrayCollection of strings you are fine.  If you have a complex Array of Objects coming back from your DB call then you will have to loop through the return and create an ArrayCollection of Strings in your result handling function.

           

           

          • 2. Re: How can I bind an inline combobox component to an array collection ?
            majester8425 Level 1

            The problem is that the inLineEditor can not see that declarartion.

             

            I am getting the data fine and fully population a datagrid, but there seems to be no way for me to tell the component combobox to use the arraycollection I declared and loaded

            • 3. Re: How can I bind an inline combobox component to an array collection ?
              ArrowUpRight

              if you post the exactly same code that you use? If so, try to change {theDataAc} to a "{theDataAc}" and the dataprovider to a dataProvider, i mean syntaxis of the code, it should work

              • 4. Re: How can I bind an inline combobox component to an array collection ?
                majester8425 Level 1

                This was way easier than I had expected

                 

                In the datagrid I added the getData to Set the current data value

                 

                 

                 

                <mx:DataGridColumn

                     headerText="Owned By"

                     rendererIsEditor="true"

                     width="200"

                     dataField="FULLNAME"

                     itemRenderer="renderers.EmpPicker"

                     editorDataField="getData"/>

                 

                In the ItemRenderer I have a function to set the data to the current value of the datagrid getData and the component references dataProvider="{parentDocument.empDataAc}" rwhich sets the remainder of the data in the combox. Easy !

                 

                 

                 

                 

                <s:MXDataGridItemRenderer

                 

                     xmlns:fx="

                http://ns.adobe.com/mxml/2009"

                     xmlns:s="

                library://ns.adobe.com/flex/spark"

                     xmlns:mx="

                library://ns.adobe.com/flex/mx"

                     focusEnabled="

                false">

                 

                 

                 

                 

                 

                    

                 

                     <s:states>

                 

                 

                 

                          <s:State name="normal"/>

                 

                 

                 

                     </s:states>

                 

                 

                 

                 

                     <fx:Script>

                 

                 

                          <![CDATA[

                 

                 

                               import flash.display.Sprite;

                 

                 

                               import spark.events.IndexChangeEvent;

                 

                 

                 

                 

                               public function get getData():String

                               {

                 

                                    /*********************************************************/

                 

                 

                 

                                    /* Without this try code I kept getting an error of 1069 */

                 

                 

                 

                                    /* when scrolling the main table. */

                 

                 

                 

                                    /*********************************************************/

                 

                 

                 

                                    var ErrorOccuredLv:Boolean = false;

                 

                                    var returnValLv:String = super.data.FULLNAME;

                 

                 

                                    try

                 

                 

                 

                                              super.data.OWNER_EMP_ID = ddl.selectedItem.EMP_ID;

                 

                                              trace(ddl.selectedItem.EMP_ID);

                 

                                              trace(super.data.OWNER_EMP_ID);

                                         }

                 

                                    catch(e:Error)

                                    {

                 

                                         trace("Error Ignored");

                                    }

                 

                 

                                    return returnValLv;

                               }

                 

                          ]]>

                 

                     </fx:Script>

                 

                 

                 

                 

                    

                     <!-- See http://bugs.adobe.com/jira/browse/SDK-27783 re open in combobox -->

                 

                 

                 

                 

                 

                     <s:ComboBox

                          id="

                ddl"

                          itemCreationPolicy="

                immediate"

                          includeIn="

                normal"

                          open="ddl.skin[

                'dropDown'].owner = this"

                          labelField="

                FULLNAME"

                          width="

                150"

                          selectedItem="

                {data.FULLNAME}"

                          dataProvider="

                {parentDocument.empDataAc}">

                 

                 

                 

                 

                 

                     </s:ComboBox>

                 

                </s:MXDataGridItemRenderer>

                </s:MXDataGridItemRenderer>