5 Replies Latest reply on Jun 1, 2009 1:36 PM by KNamuduri

    Problem Binding data to ComboBox

    KNamuduri

      Hi All,

       

      I am have been trying to do simple data to Combox using remote object.

       

      When I bind the data to DataGrid, I can see the data coming through. But when trying to assign it to Combobox by converting the result of remote object to Arraycollection. I have also provided the labelfield of the combobox but still no luck.

      I am providing the code below. Please help I need to finish a presentation.

       

      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" applicationComplete="LoadDomains()" xmlns:ns1="Components.*">
                  <mx:Script>
                  <![CDATA[
                  import mx.controls.Alert;
                  import mx.utils.ArrayUtil;
                  import mx.events.DropdownEvent;
                  import mx.collections.ArrayCollection;
                  import mx.rpc.events.ResultEvent;
                  import mx.rpc.events.FaultEvent;
                 
                  [Bindable] public var dpItemType:ArrayCollection;
                        
                  private function LoadDomains():void
                  {
                 
                  rptRoDomains.getDomains.send();
                  //    dpItemType = new ArrayCollection(ArrayUtil.toArray(rptRoDomains.getDomains.lastResult));
                      //    this.ItemTypeRO.getItemTypeByDom.send();
                  }
                  ]]>
                  </mx:Script>

      //Remote Objec call
      <mx:RemoteObject id="rptRoDomains"  destination="domains" showBusyCursor="true"  fault="Alert.show(event.fault.faultString, 'Error');"/>

      <mx:HDividedBox>

      // Assiging it to Data grid which works
              <mx:DataGrid id="dgDomList"   dataProvider="{rptRoDomains.getDomains.lastResult}" width="30%" height="100%"   >
               <mx:columns>
              <mx:DataGridColumn dataField="dom" headerText="Domain" />
              </mx:columns>
              </mx:DataGrid>
              <mx:HBox>

       

      // Problem Area

      <mx:ComboBox id="cbItemType" width="150" prompt ="Select the ItemType " labelField="dom" dataProvider="{ArrayUtil.toArray(rptRoDomains.getDomains.lastResult)}"  >
         
      </mx:ComboBox>

       

      </mx:HBox>
      </mx:HDividedBox>

       


      </mx:Application>

        • 1. Re: Problem Binding data to ComboBox
          Flex harUI Adobe Employee

          Did you try:

           

          <mx:ComboBox id="cbItemType" width="150" prompt ="Select the ItemType " labelField="dom" dataProvider="{rptRoDomains.getDomains.lastResult}"  >

               

           

          Alex Harui

          Flex SDK Developer

          Adobe Systems Inc.

          Blog: http://blogs.adobe.com/aharui

          • 2. Re: Problem Binding data to ComboBox
            *Prashant Shelke* Level 4

            Ensure that Objects present in your arrayCollection must contains properties data & label then only data will get render & also check that what length your getting for arrayCollection it should > 0


            Thanks.

            • 3. Re: Problem Binding data to ComboBox
              KNamuduri Level 1

              Hi Alex,

               

              I did try this option, but no luck.

               

              Karunya

              • 4. Re: Problem Binding data to ComboBox
                Flex harUI Adobe Employee

                What did you get?  Can you show a complete example in 20 lines or so?

                 

                Alex Harui

                Flex SDK Developer

                Adobe Systems Inc.

                Blog: http://blogs.adobe.com/aharui

                • 5. Re: Problem Binding data to ComboBox
                  KNamuduri Level 1

                  Hi Alan,

                   

                  I have written couple of JAVA classes to query the database which returns the List Object which is being called by Remote Object.

                   

                  In the Flex I am callling the Remote object and binding the data to DataGrid and ComboBox. Data comes out fine in Datagrid not the ComboBox, I Get Object ,Object in the drop even after I have specified the labelField attribute in the ComboBox.

                   

                  Here is the Flex Code :

                   

                  <?xml version="1.0"?>

                   

                  <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"  applicationComplete="LoadDomains()" xmlns:ns1="Components.*">
                              <mx:Script>
                              <![CDATA[
                              import mx.controls.Alert;
                              import mx.utils.ArrayUtil;
                              import mx.events.DropdownEvent;
                              import mx.collections.ArrayCollection;
                              import mx.rpc.events.ResultEvent;
                              import mx.rpc.events.FaultEvent;
                             
                              [Bindable] public var dpItemType:ArrayCollection;
                             
                          [Bindable] public var acLength:int;
                             
                              private function LoadDomains():void
                              {
                                     
                              rptRoDomains.getDomains.send();
                              }
                             
                          private function getLisOfDomainsResultHandler(evt:ResultEvent):void
                          {
                             
                              var domainList:Array = rptRoDomains.getDomains.lastResult as Array;
                              // fill the dataProvider with the data send back from the database
                              this.dpItemType = new ArrayCollection(domainList);
                              Alert.show( dpItemType.length.toString(),"Length of ArrayCollection");           
                          }
                              ]]>
                              </mx:Script>


                  <mx:RemoteObject id="rptRoDomains"  destination="domains" showBusyCursor="true"  fault="Alert.show(event.fault.faultString, 'Error');">
                          <mx:method name="getDomains" result="this.getLisOfDomainsResultHandler(event)" />

                  </mx:RemoteObject>

                   

                   

                   

                  <mx:HDividedBox>
                     
                          <mx:DataGrid id="dgDomList"   dataProvider="{rptRoDomains.getDomains.lastResult}" width="30%" height="100%"   >
                           <mx:columns>
                          <mx:DataGridColumn dataField="dom" headerText="Domain" />
                          </mx:columns>
                          </mx:DataGrid>
                          <mx:HBox>

                   

                   

                   


                  <mx:ComboBox id="cbItemType" width="150" prompt ="Select the Domain "
                      labelField="dom" dataProvider="{dpItemType}"  >
                         
                  </mx:ComboBox>

                   

                  </mx:HBox>
                  </mx:HDividedBox>

                   


                  </mx:Application>

                   

                   

                  Thanks for the help.

                   

                  Karunya