7 Replies Latest reply on Jan 5, 2012 12:33 AM by lseymore

    DropDownList / ComboBox DataProvider Issue

    lseymore

      In this example I have an ArrayCollection (values) that serves as a DataProvider and a Bindable field (value).  I would like to twoWay bind the value and dynamically load the values.  When dynamically loading the values, my bounded value is null.

       

      I have two applications below, in the first example the dataprovider is initialized with all its values and the behavior is correct:

       

      <?xml version="1.0"?>

      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark">

        <s:layout>

          <s:VerticalLayout/>

        </s:layout>

        <fx:Declarations>

          <fx:String id="value">B</fx:String>

          <s:ArrayCollection id="values">

            <fx:String>A</fx:String>

            <fx:String>B</fx:String>

            <fx:String>C</fx:String>

          </s:ArrayCollection>

        </fx:Declarations>

        <s:ComboBox id="comboBox" selectedItem="@{value}" dataProvider="{values}"/>

        <s:TextInput text="@{value}"/>

      </s:Application>


       

      In the second example the dataprovider is loaded dynamically, which is typical for a data driven application.  Now the bounded value is lost:

       

      <?xml version="1.0"?>

      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark">

        <fx:Script><![CDATA[

          private function comboxCreated():void {

            values.addItem("A");

            values.addItem("B");

            values.addItem("C");

          }

          ]]></fx:Script>

        <s:layout>

          <s:VerticalLayout/>

        </s:layout>

        <fx:Declarations>

          <fx:String id="value">B</fx:String>

          <s:ArrayCollection id="values"/>

        </fx:Declarations>

        <s:ComboBox id="comboBox" selectedItem="@{value}" dataProvider="{values}" creationComplete="comboxCreated()"/>

        <s:TextInput text="@{value}"/>

      </s:Application>

       

      Is there any recommended / elegant solution to fix this issue?

      Kind Regards

        • 1. Re: DropDownList / ComboBox DataProvider Issue
          Flex harUI Adobe Employee

          Try

           

          private function comboxCreated():void {
          
                var newvalues:Array = [“A”, “B”, “C”];
          
                values = new ArrayCollection(newValues);
              }
          

           

          • 2. Re: DropDownList / ComboBox DataProvider Issue
            lseymore Level 1

            Sorry, no this has the exact same effect.

            • 3. Re: DropDownList / ComboBox DataProvider Issue
              Flex harUI Adobe Employee

              Try replacing <s:ArrayCollection id=”values”> with

               

              public var values:ArrayCollection;

               

               

              If that doesn’t work, post what you have.

              • 4. Re: DropDownList / ComboBox DataProvider Issue
                lseymore Level 1

                Hi HarUI,

                 

                I don't want to offend you, but I posted the full sample application code snippets in the post.  This was so that you could run the code yourself.  If you get the code working on your side you can supply the solution, I've tried a million and two things already.

                 

                Regards

                • 5. Re: DropDownList / ComboBox DataProvider Issue
                  EricJ32 Level 1

                  I tried this and it seems to work fine - just moved the setting of the value of "value" to the creationComplete handler:

                   

                  <?xml version="1.0"?>

                  <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark">

                    <fx:Script>

                                      <![CDATA[

                                                private function comboxCreated():void {

                                                          values.addItem("A");

                                                          values.addItem("B");

                                                          values.addItem("C");

                   

                                                          value="B";

                                                }

                                      ]]>

                   

                    </fx:Script>

                    <s:layout>

                    <s:VerticalLayout/>

                    </s:layout>

                    <fx:Declarations>

                    <s:ArrayCollection id="values"/>

                    <fx:String id="value"/>

                    </fx:Declarations>

                            <s:ComboBox id="comboBox" selectedItem="@{value}" dataProvider="{values}" creationComplete="comboxCreated()"/>

                            <s:TextInput text="@{value}"/>

                  </s:Application>

                  • 6. Re: DropDownList / ComboBox DataProvider Issue
                    ibran.pb

                    <mx:ComboBox id="batchno" dataProvider="{comboBoxArray}" width="160" prompt="Select a Batch No"  >

                     

                                                  </mx:ComboBox>

                     

                    <fx:Script>

                                        <![CDATA[

                     

                     

                    [Bindable]

                                                  public var comboBoxArray:Array = ["m6c",

                                                            "m6d",

                                                            "m6e",

                                                            "m6f"];

                    ]]>

                              </fx:Script>

                     

                    do this it will work.

                    • 7. Re: DropDownList / ComboBox DataProvider Issue
                      lseymore Level 1

                      Hi Eric,

                       

                      Thanks a lot, that worked like a charm.