4 Replies Latest reply on Jun 7, 2007 4:21 AM by csawall

    Problem setting Index value on ComboBox

      I am running into a problem with setting the index on a dropdown box. I will try to give as much detail as possible. From what I can tell, it should be working and does, but only for one item. If anyone can suggest a different group to post to, let me know. I can not find a solution anywhere.

      I have the following code to show a combobox. The data is derived from a XML config file. The combobox itself works fine and does in fact show all of the data from the XML config file.

      <mx:Label text="Status" width="55"/>
      <mx:ComboBox id="uxstatus" dataProvider="{_xmlVulnStatus}" labelField="status"/>

      The part of the XML config file that is used to populate the combobox.

      <status>In Progress</status>

      Now, when a user selects an item from a separate datagrid, on change I have it run the following function. The function reads in the data, parses it and compares the "status" value from the datagrid info with the "status" options in the XML config file. When it matches, it sets the index number for the combobox so it shows the right data. My problem is below the function.

      public function parseMSVulnStatus(evt:Event):void {
      var xmlMSV:XML = XML(msdetailed.selectedItem); //the host dataProvider item
      //trace ("MS Vuln status = "+xmlMSV.status);
      for ( var MSVi:Number=0; MSVi<_xmlVulnStatus.length(); MSVi++ ) { //loop over the items in the dataProvider
      var sDataValueCurMSV:String = _xmlVulnStatus[MSVi].valueOf(); //get the current item.data value
      if ( sDataValueCurMSV == xmlMSV.status ) { //compare desired value to current item.data value
      mx.controls.Alert.show("match found - MS Vuln status = "+xmlMSV.status +" and MSVi = " +MSVi);
      msstatus.selectedIndex = MSVi; //set the seletedIndex of the combo box
      else {msstatus.selectedIndex = -1}
      if (msdetailed.selectedItem.falsepos=='Y') {msfalsepos.selected=true;}

      The problem. If the value from the datagrid is "Closed", it shows the index as being "2" and sets the combobox index appropriately and displays "Closed". The alert box is displayed (for testing) to show the values.

      If the value from the datagrid is either "Open" or "In Progress", it does show the proper index as being either 0 or 1, respectively and shows the alert box. However, the combobox appears to be set to -1. I have verified the data is set properly in the database (which is what populates the datagrid).

      Any thoughts on this? Based on my alert box, it appears that the data is seen properly and that it knows how to set the index of the combobox.... it's just not happening (unless it's "Closed").

      Thanks in advance.