Skip to content Skip to sidebar Skip to footer

Binding Dataset To A Combobox In Wpf

I've a problem. I'm not a WPF master, but I've a homework to complete. I'm trying to bind my dataset from my database to a combobox. I've done this in Windows Form Application, but

Solution 1:

If the name of your columns are "description" and "type_id" you can just do this:

category_select.DisplayMemberPath = "description";category_select.SelectedValuePath = "type_id";

As a suggestion, you could set the ItemSource property instead the DataContext in your code begind:

category_select.ItemSource= ds.Tables["t"].DefaultView;

So, you don't have to set that property (ItemSeource) in your view:

<ComboBoxName="category_select"></ComboBox>

Also you can do this:

<ComboBoxName="category_select"DisplayMemberPath = "description"SelectedValuePath = "type_id"></ComboBox>

And don't set those properties in your code behind.

Solution 2:

category_select.ItemsSource = ds.Tables["t"].DefaultView;category_select.DisplayMemberPath = "description";category_select.SelectedValuePath = "type_id";

Post a Comment for "Binding Dataset To A Combobox In Wpf"