Skip to main content

Microsoft Silverlight

Answered Question Combobox Binding to SQL DatabaseRSS Feed

(0)

Walesman
Walesman

Member

Member

0 points

7 Posts

Combobox Binding to SQL Database

Could someone please provide or direct me to a 'simple' example of bindng data to a combobox. I have found many articles in various forums on binding to a combobox, but they all seem to deviate from the simple scenario I am trying to replicate.

I am using SL3, RIA Services, Entity Framework and the NorthWind DB. All I want to do is create a combobox and bind to the the 'CategoryName' column from the Categories table. I create the relevant Data Model, Service, Domain Data Source and bindins in xaml, but I dont get the correct content. What I see in the resulting combobox is

Category 1

Category 2

Category 3

 etc

It appears to be a binding issue, but I am at a loss. If anyone has a simple example to show me the error of my ways I would greatly appreciate it.

Thanks

 

 

 

 

 

 

mchlsync
mchlsync

Star

Star

14566 points

2,730 Posts

Silverlight MVP

Re: Combobox Binding to SQL Database

Hello,

Are you seeing the type of object instead of CategoryName? I think you can try setting CategoryName to DisplayMemberPath of Combobox.

For example:

<ComboBox x:Name="uxd_Category"

ItemsSource="{Binding CategoryList}"

DisplayMemberPath="CategoryName"

/>

(If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

Regards,
Michael Sync
Silverlight MVP

Blog : http://michaelsync.net


Walesman
Walesman

Member

Member

0 points

7 Posts

Re: Combobox Binding to SQL Database

Thanks for your response  Michael. Actually, it was quiet simple in then end (see below) and I dont know what I was doing wrong.

In your xaml code, what does the 'DisplayMemeberPath' do differently from what I have below.

Thanks

Phillip

<ComboBox x:Name="cmbCategories" Width="150" ItemsSource="{Binding}">

<ComboBox.ItemTemplate>

<DataTemplate>

 

 

<StackPanel Orientation="Horizontal">

<TextBlock Margin="5,0,0,0" Text="{Binding Path=CategoryName}" Width="100"/>

</StackPanel>

 

</DataTemplate>

</ComboBox.ItemTemplate>

</ComboBox>

bbakermai
bbakermai

Member

Member

230 points

151 Posts

Answered Question

Re: Combobox Binding to SQL Database

Did you look at this blog post?

 

If this has answered your question, please hit the Mark as Answered link. Thanks!

Bob Baker
MicroApplications, Inc.
Orlando .Net Users' Group
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities