C#
MainDataContext db = new MainDataContext();
var cat = from p in db.Categories
select p;
categoriesComboBox.ItemsSource = cat;
categoriesComboBox.SelectedValuePath = "ID";
categoriesComboBox.DisplayMemberPath = "CatName";
XAML
<Custom:DataGridComboBoxColumn
Width="1*" x:Name="categoriesComboBox"
Header="Category"
ItemsSource="{Binding}"
SelectedValueBinding="{Binding Path=Category}"
SelectedValuePath="ID"
DisplayMemberPath="CatName"
/>
Now the thing is i can see the name in the comobox when it loads... when i click on the combobox the dropdown shows me MainDataContext.Category for each and开发者_Go百科 every item...
when i click on any of the drop down items.. its select the correct value and.. showing me in the combobox...
You should not set categoriesComboBox.ItemsSource = cat;
yourself, try doing it with the data context: categoriesComboBox.DataContext = cat
. Anyway, you've got the needed bindings in your XAML.
Hope that this is your actual problem (since I didn't manage to understand what the problem is from your question).
Edit: from your images, you need to specify a DataTemplate
for your type MainContext.Category
. Without it, the default template is used, which just outputs the string representation.
精彩评论