populating combobox asynchronasly

Posted on 2010-01-02
Last Modified: 2013-11-12
can any one tell me how u can populate 2nd combobox using first combobox selection in Silverlight3 but i need it asynchronasly like ajax.please give me code example
Question by:farjack1
    LVL 27

    Accepted Solution

    In the code below, I have a list of states and once the user selects a state, all the cities of the state appear in the second combo box.

    // xaml code:
    <Grid x:Name="LayoutRoot">
        <Grid.ColumnDefinitions >
            <ColumnDefinition />
            <ColumnDefinition />
            <RowDefinition />
            <RowDefinition />
        <ComboBox Name="StateComboBox" Grid.Row="0" Grid.Column="0" Height="35"
                  SelectionChanged="StateComboBox_SelectionChanged" Width="75" />
        <ComboBox Name="CityComboBox" Grid.Row="0" Grid.Column="1" Height="35"
                  Width="150" />
        <TextBlock Name="MessageBlock" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2"
                   Text="Loading Cities..." FontSize="15" />

    // code-behind
    public partial class MainPage : UserControl
        // add Service Reference:
        // to the SL project
        public MainPage()
            Loaded += MainPage_Loaded;

        void MainPage_Loaded(object sender, RoutedEventArgs e)
            MessageBlock.Visibility = Visibility.Collapsed;

        private void StateComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
            MessageBlock.Visibility = Visibility.Visible;
            USZipSoapClient zipSoapClient = new USZipSoapClient();
            zipSoapClient.GetInfoByStateCompleted += ZipSoapClient_GetInfoByStateCompleted;
            string stateCode = StateComboBox.SelectedItem.ToString();

        void ZipSoapClient_GetInfoByStateCompleted(object sender, GetInfoByStateCompletedEventArgs e)
            string xmlResult = e.Result.ToString();
            XmlReader resultXml = XmlReader.Create(new StringReader(xmlResult));
            while (resultXml.Read())
                if (resultXml.NodeType != XmlNodeType.Element) continue;
                switch (resultXml.LocalName.ToLower())
                    case "city":
                        string cityName = resultXml.ReadInnerXml();
            MessageBlock.Visibility = Visibility.Collapsed;

    Author Comment

    if i do not use web service and getting data from database still silverlight will populate cityCombobox asynchronously?
    LVL 27

    Expert Comment

    Yes, that is true. A good number of things in Silverlight operate asynchronously.

    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

    In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
    This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…

    761 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

    8 Experts available now in Live!

    Get 1:1 Help Now