6 Replies Latest reply on Jun 30, 2009 6:30 AM by lee704

    Simple example of a combobox displaying data from a CF datasource

    lee704 Level 1

      Can anyone point me to a simple example of a Flex 3 combobox that displays data from a ColdFusion datasource?  I cannot seem to find a simple example.  As always, thanks!

        • 1. Re: Simple example of a combobox displaying data from a CF datasource
          JeffryHouser Level 4

          This uses the Flextras AutoCompleteComboBox, butthe concepts are the same using a 'normal' ComboBox.

           

          Basically, make remoteObject call, set results to dataProvider of ComboBox

           

          Example: http://www.flextras.com/AutoCompleteComboBox/Samples/DBFilter/#

          Source:http://www.flextras.com/AutoCompleteComboBox/Samples/DBFilter/srcview/index.html

          • 2. Re: Simple example of a combobox displaying data from a CF datasource
            lee704 Level 1

            Thanks for the response, but the example you provided is more complex than I need.  For example, I have a simple table accessed through ColdFusion.  The table has one filed with 7 records.  I need a flex page to display that data in DataGrid, ComboBox and List controls.  The Datagrid displays the 7 records but the ComboBox and List are blank.  How do I get the values from the database to display in the BomboBox and List controls?

             

            Below is my code:

             

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"
                            creationComplete="initComponent()">

             

                <mx:Script>
                <![CDATA[
                    import mx.collections.ArrayCollection;
                    import mx.rpc.events.ResultEvent;
                    import mx.rpc.remoting.RemoteObject;
                   
                     private var currentIndex:int = 0;

             

                    private var _key:Object;

             

                    [Bindable]
                    public function get key():Object
                        {
                            return this._key;
                        }
                    public function set key(key:Object):void
                        {
                            this._key = key;
                        }

             

                     private function initComponent():void
                        {
                            refreshList(null);
                        }

             

                     public function refreshList(event:Event):void
                        {
                            this.dataManager.getRoles(this.key);
                        }
                   
                    private function getRoles_result(event:ResultEvent):void
                        {
                            this.roleList.dataProvider = event.result as ArrayCollection;
                             this.roleList.selectedIndex = this.currentIndex;
                        }
              
                ]]>
                </mx:Script>

             

                    <mx:RemoteObject
                        id="dataManager"
                        showBusyCursor="true"
                        destination="ColdFusion"
                        source="ifqgtfuses.com.vwRoles">
                        <mx:method name="getRoles" result="getRoles_result(event)" />
                    </mx:RemoteObject>

             

               <mx:Canvas width="100%" height="100%" x="0" y="0">
                    <mx:DataGrid id="roleList"
                        x="10" y="10">
                        <mx:columns>
                            <mx:DataGridColumn dataField="vchar_role" headerText="Role" />
                        </mx:columns>
                    </mx:DataGrid>
                    <mx:ComboBox x="10" y="160" id="rolesComboBox" dataProvider="{roleList.selectedIndex}"/>
                    <mx:List x="120" y="10" id="rolesList" dataProvider="{roleList.selectedIndex}"/>
               </mx:Canvas>
            </mx:Canvas>

            • 3. Re: Simple example of a combobox displaying data from a CF datasource
              LinkMc Level 1

              I am pretty sure this is what you are looking for

               

              http://blog.tygate.com/?p=463

              • 4. Re: Simple example of a combobox displaying data from a CF datasource
                DM277

                Hi,

                 

                In your code please mark the field to be shown as the labelfield

                 

                <mx:ComboBox x="10" y="160" id="rolesComboBox" dataProvider="{roleList.selectedIndex}"     

                labelField ="{Youe field Name}"

                />

                1 person found this helpful
                • 5. Re: Simple example of a combobox displaying data from a CF datasource
                  DM277 Level 2

                  Hi,

                   

                  In your code pprovide the property labelfield to display the field you wat to show in both combobox and list.

                   

                  Try changing your code as the following

                   

                  <mx:ComboBox x="10" y="160" id="rolesComboBox" dataProvider="{roleList.selectedIndex}"  labelfield = "{Your filed here}"/>
                          <mx:List x="120" y="10" id="rolesList" dataProvider="{roleList.selectedIndex}"   labelfield = "{Your field here}"/>

                   

                   

                  Hope this will help you

                   

                  Regards.

                  1 person found this helpful
                  • 6. Re: Simple example of a combobox displaying data from a CF datasource
                    lee704 Level 1

                    Right on the money.  Thanks!