Filling a ComboBox from a webservice

Posted on 2009-04-22
Last Modified: 2013-11-11
Hi, I figured out how to populate DataGrids in Flex 3, from a .Net asmx web service.  My service returns a DataTable, and this procedure is straightforward and works fine:

But I can't seem to figure out how to apply the same idea to ComboBox.  How do you populate a ComboBox from a webservice (preferably one that returns a DataTable but any format is fine)?

Question by:dparkes
    LVL 2

    Accepted Solution

    I'm not entirely sure if this will help you, but DataGrids and ComboBoxes use different dataProvider types. A DataGrid uses an ArrayCollection while a ComboBox uses an Array. When I populate an array, I use a simple for loop to iterate through the data I receive from my server. Attached is the code for how I would do it...(presumably if you've been able to populate a DataGrid you know how to read the data that you have from the server)...
    [Bindable] private var myArray:Array = new Array();
    private function populateMyArray(event:ResultEvent):void {
    	var dataObj:Object = JSON.decode(String(event.result));
    	var numChil = dataObj.NumberOfItems;
    	myArray = new Array();
    	for (var i:int=0; i<numChil; i++) {
    <mx:ComboBox dataProvider="{myArray}"/>

    Open in new window

    LVL 1

    Author Comment

    Thanks for showing me that method.  I actually figured out how to do it with my ASP.Net DataTable using the same method that I had linked above.
    It was a simple oversight on my part.  I had just needed add the 'name' tag to the ComboBox so that it matched to column name in the DataTable.
    So in my case, the Flex code is something like this:


    <?xml version="1.0" encoding="utf-8"?>
    <mx:TitleWindow xmlns:mx="" layout="absolute" width="652" height="132" title="Large Format Black &amp; White Detail" creationComplete="initApp();">
    fault="onFault(event)" />
    <mx:ComboBox x="117" y="20" width="183" id="dMediaSize" labelField="name" color="#000000"/>

    import mx.controls.Alert;
    public function initApp():void{ 
    private function onResult(event:ResultEvent):void { 
    if (event.result.Tables != null) 
    if (event.result.Tables.MediaTable != null) 
    dMediaSize.dataProvider = event.result.Tables.MediaTable.Rows; 
    catch(err:Error) {} 
    finally {} 
    private function onFault(event:FaultEvent):void {
   "Error reading data table.");

    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
    Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
    In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
    The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now