3 Replies Latest reply on Dec 11, 2007 12:37 AM by Mike B Baker

    ComboBox add new item to the list

    rkoe123 Level 1
      Hi all
      I am trying to figure out how does one add new item to the combobox.
      I have a combobox which has datasource from database, and I want to add "All" as the first item in the combobox list. So say the database table returns the list:
      "Dog", "Cat", "Horse"
      But what I want in the combobox list:
      "All", "Dog", "Cat", "Horse"

      Thanks!
        • 1. Re: ComboBox add new item to the list
          rkoe123 Level 1
          Hi all

          I need to use addChildAt(), but being new to Flex 2, can anyone kindly show me how to use the method?

          I have a compile error when I have:

          var s:String = new String("All");
          comboboxname.addChildAt(s,0);

          seems like the first paremeter being type DisplayObject doesn't like String
          • 2. Re: ComboBox add new item to the list
            Power@IT Level 1
            Hello rkoe123,
            How about to use a "Label" as the DisplayObject? Or something to be coverted to the "IUICompoent"?
            • 3. Re: ComboBox add new item to the list
              Mike B Baker
              Hi,

              You can add the 'ALL' to your dataProvider here is an example,
              <?xml version="1.0" encoding="utf-8"?>
              <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" initialize="initData()">
              <mx:Script>
              <![CDATA[
              import mx.collections.*;
              [Bindable]
              public var animalArray:ArrayCollection;

              public function initData():void {
              animalArray=new ArrayCollection(
              [{label:"CAT", data:"CAT"},
              {label:"DOG", data:"DOG"},
              {label:"HORSE", data:"HORSE"}]);




              animalArray.addItemAt({'label':'ALL','data':'ALL'},0);

              }
              ]]>
              </mx:Script>

              <mx:ComboBox id="animalComboBox" dataProvider="{animalArray}"/>

              </mx:Application>

              Hope this helps,
              Mike