10 Replies Latest reply on Nov 3, 2009 6:10 AM by iamfuric

    Combobox with dynamic dataProvider

    Zolotoj Level 3

      I have a very simple code:

       

      private function showAvailableLabels(resultXML:XML, param:Object):void

      {

       

      if (resultXML.children().length() == 0)

      Alert.show("Sku " + sku.text + " not found!", "Error");

      else

      {

      labels.dataProvider = "";

      labels.dataProvider = resultXML.availablelabels;

      labels.validateNow();

      labels.setFocus();

      labels.selectedIndex = 0;

      }

      }

       

      That code assigns different dataProvider to a combobox at the run time. I cannot get the exact pattern, but after a few times the combobox starts showing data from a previous data assignment. Do I have to refresh it somehow?

       

      Thanks

        • 1. Re: Combobox with dynamic dataProvider
          Matt Le Fevre Level 4

          a simple

           

          [comboboxname].dataprovider.refresh();

           

          command may work

          • 2. Re: Combobox with dynamic dataProvider
            Zolotoj Level 3

            Same problem.

            • 3. Re: Combobox with dynamic dataProvider
              iamfuric Level 2

              You should assign dataProvider on next refresh cicle with callLater :

               

               

              callLater(function (dp:Object):void

              {labels.dataProvider=dp},[resultXML.availablelabels]);

               

               

               

               

              • 4. Re: Combobox with dynamic dataProvider
                Zolotoj Level 3

                Nope, same ....

                • 5. Re: Combobox with dynamic dataProvider
                  paul.williams Level 4

                  No refresh / callLaters should be required. If you change the dataProvider of a ComboBox it will trigger commitProperties / updateDisplayList and refresh automatically. Use the FlexBuilder debugger or FlexSpy to inspect the contents of the ComboBox dataProvider at runtime, or provide a runnable demo of the problem.

                  • 6. Re: Combobox with dynamic dataProvider
                    Zolotoj Level 3

                    I will try to provide a workable demo, although after stripping everything out it might as well  start working.

                    I have checked incoming data and dataProvider at the run time. Both look right.

                    • 7. Re: Combobox with dynamic dataProvider
                      iamfuric Level 2

                      Hmmm,  it IS required for table , check the attached sample out ...

                      • 8. Re: Combobox with dynamic dataProvider
                        Zolotoj Level 3

                        Dont see anything attached. Sorry, I see it now.

                        • 9. Re: Combobox with dynamic dataProvider
                          Zolotoj Level 3

                          Here is a runnable demo I have put together using provided code:

                          <?xml version="1.0" encoding="utf-8"?>
                          <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
                                            xmlns:s="library://ns.adobe.com/flex/spark" creationComplete="switchDataProvider()" 
                                            xmlns:mx="library://ns.adobe.com/flex/halo" 
                                            minWidth="1024" minHeight="768">
                               <fx:Script>
                                    <![CDATA[
                                    private var model_1:XML = <VFPData>
                                                                         <availablelabels>
                                                                           <filename>193</filename>
                                                                           <id>10</id>
                                                                         </availablelabels>
                                                                       </VFPData>
                                    private var model_2:XML = <VFPData>
                                                                       <availablelabels>
                                                                         <filename>192</filename>
                                                                         <id>9</id>
                                                                       </availablelabels>
                                                                       <availablelabels>
                                                                         <filename>160down</filename>
                                                                         <id>25</id>
                                                                       </availablelabels>
                                                                    </VFPData>
                          
                                    private var current:XML = model_1;
                                    private function  switchDataProvider():void
                                    {
                                         current = current==model_1?model_2:model_1;
                                         comboBox.dataProvider = current.availablelabels;
                                    }
                                    
                                    ]]>
                               </fx:Script>
                               <mx:VBox>
                                    <mx:ComboBox id="comboBox" labelField="filename"/>
                                    <mx:Spacer height="10"/>
                                    <s:Button click="switchDataProvider()" label="Switch"/>
                               </mx:VBox>
                          </s:Application>
                          
                           
                          

                          Click on the push button and check the content of the combo, you should 192 from previous data.

                          • 10. Re: Combobox with dynamic dataProvider
                            iamfuric Level 2

                            Золотой, ты бы потрудился хотя бы САМ создать демо версию...