C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » WPF »

WPF Combobox Databind to a Dataset


Posted Date: 20 Jun 2009    Resource Type: Articles    Category: WPF
Author: ABitSmartMember Level: Diamond    
Rating: 1 out of 5Points: 15



Often there is a question on "how to bind ComboBox to a Dataset?". A short and simple answer, You cannot. The more specific answer is, you bind to a DataTable and not a DataSet.

There are two ways to accomplish this,
1. Setting the Path of the ItemsSource in XAML and then setting the DataSet as the DataContext.
XAML,

< ComboBox
x:Name="myComboBox"
ItemsSource="{Binding Path=yourTableName}">
</ComboBox>

Code behind,

DataSet ds; //ASSUMPTION: This DataSet contains a Table named yourTableName
myComboBox.DataContext = ds;


2. Setting the ItemsSource of the ComboBox to the DataTable from the DataSet.
XAML,

< ComboBox
x:Name="myComboBox">
</ComboBox>

Code behind,

DataSet ds; //ASSUMPTION: This DataSet contains a Table named yourTableName
myComboBox.ItemsSource = ds["yourTableName"];


"ds" is my DataSet object. It has a table named "yourTableName". I am binding this particular table to the ComboBox.

Have fun.



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
WPF  .  DataSet  .  Databinding  .  Combobox binding to a DataTable  .  Combobox binding to a Dataset  .  Combobox binding  .  Combobox  .  Binding to a DataSet  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: WPF Dispatcher CheckAccess and VerifyAccess Mystery
Previous Resource: WPF Timer (DispatcherTimer)
Return to Discussion Resource Index
Post New Resource
Category: WPF


Post resources and earn money!
 



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use