3 Replies Latest reply on Feb 11, 2010 2:52 PM by ndilekli

    Populating ComboBox Programatically by a Method

    ndilekli

      I am trying to populate a combobox within a method. However my combo box comes up empty. Is there a way to refresh the combobox dataProvider?

       

      Here is my code,

       

      Thanks

       

      ---------------------------

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application
          xmlns:mx="http://www.adobe.com/2006/mxml"
          styleName="plain"
          initialize="init()">

       

          <mx:Script>
              <![CDATA[

       

                  import mx.controls.Alert;
                  import mx.rpc.AsyncResponder;
                  import mx.collections.ArrayCollection;
                 
                  [Bindable]
                  public var myArray:Array;

       

                  private function init():void
                  {
                 
                  myArray.push("one");
                  myArray.push("two");

       

                  }
              ]]>
          </mx:Script>

       


              <mx:ComboBox id="QueryComboBox" dataProvider="{myArray}"/>

       

      </mx:Application>

        • 1. Re: Populating ComboBox Programatically by a Method
          Gregory Lafrance Level 6

          You should use an ArrayCollection for the dataProvider:

           

          var myAC:ArrayCollection = new ArrayCollection(myArray);

           

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


          Greg Lafrance - Flex 2 and 3 ACE certified

          www.ChikaraDev.com

          Flex / AIR Development, Training, and Support Services

          • 2. Re: Populating ComboBox Programatically by a Method
            ndilekli Level 1

            I am sorry, I am very new to Flex and was not able to have it working with ArrayCollection either.

             

            Here is my updated code

             

            -------------------------------------------

             

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application
                xmlns:mx="http://www.adobe.com/2006/mxml"
                styleName="plain"
                initialize="init()">

             

                <mx:Script>
                    <![CDATA[

             

                        import mx.controls.Alert;
                        import mx.rpc.AsyncResponder;
                        import mx.collections.ArrayCollection;
                       
                        [Bindable]
                        public var myArray:Array;
                        [Bindable]
                        public var myAC:ArrayCollection = new ArrayCollection(myArray);

             

                        private function init():void
                        {
                       
                        myArray.push("one");
                        myArray.push("two");

             

                        }
                    ]]>
                </mx:Script>

             


                    <mx:ComboBox id="QueryComboBox" dataProvider="{myAC}"/>

             

            </mx:Application>

            • 3. Re: Populating ComboBox Programatically by a Method
              ndilekli Level 1

              OK Fixed now

               

              -----------------------------------

               

               

              <?xml version="1.0" encoding="utf-8"?>
              <mx:Application
                  xmlns:mx="http://www.adobe.com/2006/mxml"
                  styleName="plain"
                  initialize="init()">

               

                  <mx:Script>
                      <![CDATA[

               

                          import mx.controls.Alert;
                          import mx.rpc.AsyncResponder;
                          import mx.collections.ArrayCollection;
                         
                          [Bindable]
                          public var myAC:ArrayCollection = new ArrayCollection();

               

                          private function init():void
                          {
                         
                          myAC.addItem('new element');
                          myAC.addItem('new element2');

               

                          }
                      ]]>
                  </mx:Script>

               


                      <mx:ComboBox id="QueryComboBox" dataProvider="{myAC}"/>

               

              </mx:Application>