5 Replies Latest reply on Aug 28, 2009 1:13 PM by David_F57

    cannot get the selected item on dropdownlist or combobox to work... please help..

    cyber0897 Level 1

      hey guys... im havin a bit of trouble trying to figure this out...

      basically i have a dropdownlist and a combobox set up like this:

       

      <mx:FormItem label="Error Page">

           <s:DropDownList id="errorPage" selectedItem="{modules.SiteEditor.siteEditor.siteListData.homePage}" requiresSelection="true" width="475"
                          dataProvider="{modules.PageEditor.pageEditor.pageListData}" labelField="Value" />
      </mx:FormItem>
      <mx:FormItem label="Home Page">

           <mx:ComboBox id="homePage" width="475"
                          dataProvider="{modules.PageEditor.pageEditor.pageListData}" labelField="Value" />
      </mx:FormItem>

       

      the dataprovider comes back as an arraycollection, couple of key values in there are named: "Key" and "Value", value contains the string name of the item, and the Key represents the Id of that item.

       

      the selected item "modules.SiteEditor.siteEditor.siteListData.homePage" is an integer value, forexample 11, i need that to be the selected value.

       

      for example if the ....siteListData.homePage is 11, then i need 11 to be selected from the ....pageListData arraycollection... there should be a 11 as one of the values in "Key" part of the array collection

       

       

      please help... ive spend more than a day on this stupid issue...

       

      thank you in advance!!

        • 1. Re: cannot get the selected item on dropdownlist or combobox to work... please help..
          David_F57 Level 5

          selectedvalue =modules.PageEditor.pageEditor.pageListData[homePage.selectedIndex].Key

           

           

          David.

          • 2. Re: cannot get the selected item on dropdownlist or combobox to work... please help..
            cyber0897 Level 1

            hey david!! thank you soo much for commin to my rescue again!! i really really appretiate it!!

             

            the thing is, i tried doin selectedItem="{modules.PageEditor.pageEditor.pageListData[homePage.selectedIndex].Key}" but it gave me a few warnings and it did not work...:(

             

            the selection key is commin from modules.SiteEditor.siteEditor.siteListData.homePage


            and the array collection in the dataprovider is modules.PageEditor.pageEditor.pageListData which contains "Key" and "Value"

             

            what i tried doin is, calling this following function on initiate, mouseover, and mouse out but unfortunately it wont call it unless its mouse over or out... i need it to be called as soon as i change the viewstack

             

            public function findSelectedItem():void{
                for each(var item:Object in modules.PageEditor.pageEditor.pageListData){
                    if(item.Key == modules.SiteEditor.siteEditor.siteListData.homePage){
                        homePage.selectedItem = item;
                    }
                    if(item.Key == modules.SiteEditor.siteEditor.siteListData.errorPage){
                        errorPage.selectedItem = item;
                    }
                }
            }

             

             


            again thank you soo much david!!

            • 3. Re: cannot get the selected item on dropdownlist or combobox to work... please help..
              David_F57 Level 5

              When you use a viewstack the "pages" of the stack are not created immediately, you can override this default behaviour by using the creation policy in the viewstack declaration.

               

              <mx:ViewStack x="518" y="220" id="viewstack1" width="200" height="200" creationPolicy="all">

              this way you can perform operations on any of the viewstacks objects in your applications creationcomplete code.
              David.

              1 person found this helpful
              • 4. Re: cannot get the selected item on dropdownlist or combobox to work... please help..
                cyber0897 Level 1

                i tried doin that in my mainWindow.mxml.... the code inside the application tags

                 

                <mx:ViewStack id="myViewStack" width="100%" height="100%">
                      <mx:Canvas id="PanelEditor">
                             <PanelEditor:PanelEditor />
                      </mx:Canvas>
                      <mx:Canvas id="PageEditor" width="100%" height="100%"
                               hide="modules.PageEditor.pageEditor.init();"
                               show="modules.PageEditor.pageEditor.init(); mainScript.loadingBar.loading(mainScreen);">
                                <PageEditor:PageEditor />
                      </mx:Canvas>
                       mx:Canvas id="SiteEditor" width="100%" height="100%" creationPolicy="all"
                               hide="modules.SiteEditor.siteEditor.init(); modules.PageEditor.pageEditor.init();"
                               show="modules.PageEditor.pageEditor.init();
                                            modules.SiteEditor.siteEditor.init(); mainScript.loadingBar.loading(mainScreen);">
                                <SiteEditor:SiteEditor />
                        </mx:Canvas>
                </mx:ViewStack>

                 

                i tried doin

                <mx:ViewStack id="myViewStack" width="100%" height="100%" creationPolicy="all">

                ...

                ...

                </mx:ViewStack>

                 

                 

                and inside my SiteEditor component i had

                <s:Group xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/halo" width="100%" height="100%" initialize="init();" xmlns:SiteEditor="modules.SiteEditor.*" creationComplete="findSelectedItem(); Alert.show('here');"  >

                ...

                ...

                </s:Group>

                 

                and it only alerted once, and only updated my dropdown only once... and that was when i first went to that component... but after that, it did not work...

                also iw as wondering if you had a chance to take a look at my project... the zipfile link i pm'd you.. ??

                 

                thanks david!!

                • 5. Re: cannot get the selected item on dropdownlist or combobox to work... please help..
                  David_F57 Level 5

                  Hi,

                   

                  Below is a very simplistic approach to setting the indexs of 2 lists depending on their key value, hopefully this will help . As for the other problem I can't see at this point why you have an issue but I will take a better look at it in the morning(hang on it is morning) ok later today, its 6am time to get some sleep.

                  ?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"

                                    xmlns:mx="library://ns.adobe.com/flex/halo" minWidth="1024" minHeight="768"

                                    creationComplete="app_creationCompleteHandler(event)">

                       <fx:Script>

                            <![CDATA[

                                 import mx.events.FlexEvent;

                                 import mx.collections.ArrayCollection;

                                 [Bindable] private var ArrPage: ArrayCollection =

                                              new ArrayCollection([

                                                   {Key:1,Value:'First Page'},

                                                   {Key:2,Value:'Second Page'},

                                                   {Key:3,Value:'Third Page'},

                                                   {Key:4,Value:'Fourth Page'},

                                                   {Key:5,Value:'Fifth Page'}]);

                                 

                                 [Bindable] private var ArrEdit: ArrayCollection =

                                             new ArrayCollection([

                                                   {Key:1,Value:'Edit One'},

                                                   {Key:2,Value:'Edit Two'},

                                                   {Key:3,Value:'Edit Three'},

                                                   {Key:4,Value:'Edit Four'},

                                                   {Key:5,Value:'Edit Five'}]);

                   

                                 protected function app_creationCompleteHandler(event:FlexEvent):void

                                 {

                                      SetLists(2);

                                 }

                   

                                 

                                 private function SetLists(value:int): void

                                 {

                                      for (var i:int=0;i < ArrPage.length;i++)

                                      {

                                           if (ArrPage[i].Key==value) pl.selectedIndex=i;

                                      }

                                      for (var j:int=0;j < ArrEdit.length;j++)

                                      {

                                           if (ArrEdit[j].Key==value) dl.selectedIndex=j;

                                      }

                                 }

                   

                            ]]>

                       </fx:Script>

                       <s:List id="pl" x="56" y="83" dataProvider="{ArrPage}" labelField="Value"/>

                       <s:DropDownList id="dl" x="55" y="38" width="113" dataProvider="{ArrEdit}" labelField="Value"/>

                  </s:Application>