3 Replies Latest reply on Dec 12, 2007 8:15 AM by Adrian Parker

    Problem setting selected item in combo box that has XML data provider

    Adrian Parker
      Hi - new to Flex, experienced Java dev. Hoping someone can help me see the light with what should be easy but..

      I have a Flex 3 MXML application form that contains a combobox like so:
      <mx:ComboBox id="physRegion" editable="false" dataProvider="{regionRequest.lastResult.region}" />

      The combo box is populated by data provider as so:
      mx:HTTPService id="regionRequest" url="flexDAOServlet" resultFormat="e4x" method="POST">

      and the underlying XML looks like this:

      Combo box loads the XML fine; user can select an item and the appropriate value is submitted to the server no problem. My problem comes when I want to "reload" this form with the previous values.
      I can reload the text fields no problem.

      But I can't work out, in my ActionScript function, how to set the combo box so that it displays "Auckland" e.g. the item with value = 2. I return this id from the server, although I could return the XML or the label if that was going to help me solve this problem.

      I have tried physRegion.selectedItem="Auckland" - nope.
      I have tried physRegion.selectedItem = 2 - nope.
      I have tried
      var myXML:XML = XML("<region><label>Auckland</label><value>2</value></region>");
      physRegion.selectedItem = myXML;
      and - nope.

      I know I'm making a new user style mistake here (and thank you for reading this far! your patience is appreciated) but I can't for the life of me see what it is. Can anyone help?

      Much thanks in advance for any clues. Apart from this, I'm loving Flex.
      kind regards