2 Replies Latest reply on May 28, 2008 12:24 PM by Solerous

    Combobox set selectedItem

    Solerous Level 1
      I've seen a half dozen solutions to this on the internet but somehow they don't work. Basically I just want to set the selectedItem of a combobox:

      <mx:Combobox id="comboboxID" dataprovider="{httpserv.lastresult.system.data}"/>

      // actionscript which won't work
      comboboxID.selectedItem = "something";

      So then I tried to loop through the comboboxID.dataprovider to find the index for "something" but it won't ever give me the dataprovider strings, instead giving me errors like this:

      warning: unable to bind to property 'name' on class 'String' (class is not an IEventDispatcher)

      How can I get this working?

        • 1. Re: Combobox set selectedItem
          Gregory Lafrance Level 6
          Simplified sample code showing the error?
          • 2. Re: Combobox set selectedItem
            Solerous Level 1
            Thanks for the interest. I think the problem was somehow in the way I was defining my own custom combo box. I finally gave up and just wrote a loop to get the matching index and set it manually. May not be the best solution, but it works...

            combo.selectedIndex = setComboBox(combo, "label_name");

            private function setComboBox(box:ComboBox, val:String):int {

            for ( var i:int=0; i<box.dataProvider.length; i++ ) {

            if (box.dataProvider .name == val) { //compare desired value to current item.data value
            box.selectedIndex = i; //set the seletedIndex of the combo box
            trace("found index: ",i);
            return i;
            return 0;