What I am attempting to do is to bind the ItemSource
to all values in a table from my model and bind the SelectedValue
to the foreign key of the table that the first one is linked to. Below is what I have tried.
Note: The attribute the client_typeID is linked to is called 'ClientType'. client_type1 is what i want the View to display.
Here is my DataAccessService method for getting the list of client types:
public List<string> GetClientTypes()
{
List<string> ClientType = new List<string>();
foreach (var item in context1.Client_Type)
{
ClientType.Add(item.client_type1);
}
return ClientType;
}
Here is my ViewModel:
public List<string> Client_type_list
{
get { return ServerPxy.GetClientTypes(); }
}
private Entity record;
public Entity Record
{
get { return record; }
set
{
record = value;
RaisePropertyChanged("Record");
}
}
Note: ServerPxy
is my instance of the DataAccessService, Record
is the property for the entitiy table.
Here is my XAML for the ComboBox:
<ComboBox Grid.Column="3" Grid.Row="0" MaxHeight="26" Margin="2" ItemsSource="{Binding Client_type_list}" Text="{Binding Record.Client_Type.client_type1}" />
All of this provides me with the ComboBox
that has the correct ItemSource and the Correct value selected. The only issue is that when I change the SelectedItem
it updates the Client_Type table's description rather than the foreign key of the Entity table when the Update method is run.
Also I have tried to follow this example however it did not help me.
Any help would me much appreciated.