This is a migrated thread and some comments may be shown as answers.

Fill ComboBox from WebService

3 Answers 134 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Meerkat
Top achievements
Rank 1
Meerkat asked on 17 Jul 2008, 03:08 PM

Your example hand codes the data into a class which is used to fill your new combobox. I would like to do something of more practical use by filling the combobox using a webservice. It would be really great if you could tell me how this might be done. A working example would be brilliant but I realise that might be asking a bit much. If the following is too unclear to follow, any help on how to use a combox to display data returned from s web service would be very much appreciated.

WEB SERVICE

    public List<view_County> GetCounties()
    {
      DataClassesDataContext db = new DataClassesDataContext();
      var query = from d in db.view_Counties
                  select d;
      return query.ToList();
    }

(view_Counties returns a single field called County;)

XAML

<UserControl x:Class="TestTelerik.Page"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Input"
    Width="400" Height="300">

    <StackPanel x:Name="LayoutRoot">
      <telerik:RadComboBox x:Name="RadComboBox1" />
    </StackPanel>
 
</UserControl>

CODE

 void client_GetCountiesCompleted(object sender, GetCountiesCompletedEventArgs e)
    {
// These two lines do not display anything at all, so what do I need to do please.

      RadComboBox3.DataContext = e.Result;
      RadComboBox3.DisplayMemberPath = "County";
    }

Many thanks,

Pete.

3 Answers, 1 is accepted

Sort by
0
Accepted
Valeri Hristov
Telerik team
answered on 17 Jul 2008, 03:21 PM
Hello Pete,

On a first glance I could suggest trying one those two variants (I think that both of them should work):

1) Keep the existing C# and XAML and add ItemsSource={Binding} in RadComboBox tag:
<telerik:RadComboBox x:Name="RadComboBox1" ItemsSource={Binding} />

or
2) Instead of setting DataContext=e.Result in the C# client code, set ItemsSource
RadComboBox3.ItemsSource = e.Result;

Let me know if those do not work for you and I will prepare a working example.

Regards,
Valeri Hristov (Silverlight Team)
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Meerkat
Top achievements
Rank 1
answered on 17 Jul 2008, 04:20 PM

Hi Valeri,

Both your solutions worked perfectly!
Thank you very much for your prompt and helpful reply,

Regards,

Pete.

0
Matthew
Top achievements
Rank 1
answered on 20 Oct 2011, 05:01 AM
I have tried the suggestions listed above, but I am getting the following result.

http://i.imgur.com/ygoDG.png

There are 4 items being returned and bound to the control, but the Display and Value Member Paths are all null...?

If I do not provide Display and Value Member Paths then it displays 4 items in the dropdown as "Namespace.Class".
Tags
General Discussions
Asked by
Meerkat
Top achievements
Rank 1
Answers by
Valeri Hristov
Telerik team
Meerkat
Top achievements
Rank 1
Matthew
Top achievements
Rank 1
Share this question
or