Click here to Skip to main content
15,888,980 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Using the entity framework and WPF I want to have a combobox that
1. populate the items from a list that I refer to in XAML. The list is defined in code. The list has two columns: “ValueCh” and “Text”.
2. All the “Text” entries are to be shown in the dropdown list
3. The “ValueCh” is to be fetched from a database field when displaying the combobox and the corresponding “Text” is to be displayed. When updating, the “ValueCh” that is corresponding to the “Text” is to be updated in the databae field. (Normal binding)

I have tried numerous ways to achieve this. The list is an “ObservableCollection< >” inherited class where the constructor fills in the list. In the Window.Resources section I have this:

HTML
  <my:VisningsTyper x:Key="NummereringListe"/>
<CollectionViewSource x:Key="NummereringListeSource"  Source="{Binding  Source={StaticResource NummereringListe}}"/>

In a Datagrid in a DataTemplate I have this:

HTML
 <ComboBox ItemsSource="{Binding Source={StaticResource NummereringListe}, Mode=OneTime}" 
DisplayMemberPath="Tekst" SelectedValuePath=" NummereringListe.VerdiCh"
SelectedItem="{Binding Path= Visning }" />

In the database it tries to save a value that is the name of the items in the “NummereringListe” prefixed with the name of its namespace. By the way, changing the SelectedValuePath value has no effect, neither has changing it to a random value or remove it. Also, substitute “NummereringListe” with “NummereringListeSource” has any effect.

What am I doing wrong? What am I to do?
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900