SIGN UP MEMBER LOGIN:    
ARTICLE

SelectedValue and SelectedValuePath in Silverlight 4

Posted by Diptimaya Patra Articles | Silverlight with C# May 07, 2010
In this article we will see about SelectedValue and SelectedValuePath while Binding. This feature is added in Silverlight 4.
Reader Level:
Download Files:
 

Introduction

In this article we will see about SelectedValue and SelectedValuePath while Binding. This feature is added in Silverlight 4.

SelectedValue and SelectedValuePath

These properties enable a ComboBox to behave as a look up table, that means a value can be displayed in ComboBox but when selected another property would be selected.

Let's do a sample where we can see it.

Let's have a ComboBox to display the data and a TextBlock which will display another property of the bound data of ComboBox.

Let's have sample data which can be bound to ComboBox.

image1.gif

The above class represents a sample Employee Entity structure.

image2.gif

Now in xaml we need to do proper binding as follows:

image3.gif

As you see in above xaml display, we have set the SelectedValuePath which is different from the displaying Path. In our case SelectedValuePath is "EmailID" and for display it is "EmployeeName".

In the TextBlock, the Text property is bound to the SelectedValue of the Element ComboBox.

Now let's run the application and see the Properties in action.

image4.gif

That's it. It's easy in Silverlight 4 to use SelectedValue and SelectedValuePath for displaying one property and displaying another property on selection.

Hope this article helps. 

Login to add your contents and source code to this article
share this article :
post comment
 

Hi, In your code iam getting this error for silverlight Combobox SelectedValuePath was not found in type combobox. Regards Ram

Posted by ramesh nalla Feb 10, 2012

Thanks for the useful post, but what about Contact? can we display it in another text block besides the Email textblock? i means..1 combo box and more text blocks...

Posted by King Dragons May 06, 2011

Hi,thanks for wonderful article.can u please suggest how to pass those two values to another page.I m unable to retrieve value selected in combobx as slectedvalue is bound to value in textbox.Is ther any way to get the value in combobox.Please suggest me.I m in great need of this.If i m using combox.selectedvalue i m getting value in textbox.but i need selected value in combobx.Thanks.Smitha.

Posted by smitha ch Feb 10, 2011
Nevron Gauge for SharePoint
Become a Sponsor
PREMIUM SPONSORS
  • Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Become a Sponsor