In View I have Combobox:
<ComboBox Name="Typ" Grid.Column="5" Grid.Row="0" Margin="3 5 3 5"
SelectedItem="{Binding Path=typ, UpdateSourceTrigger=PropertyChanged}">
<ComboBoxItem Content="ATMA"/>
<ComboBoxItem Content="NTP" />
<ComboBoxItem Content="ATMA" />
</ComboBox>
I want get Selected ComboBoxItem in ViewModel and save it to database
public string typ
{
get
{
return item.typ;
}
set
{
if (value != item.typ)
{
item.typ = value;
OnPropertyChanged(() => typ);
}
}
}
When I want save item.typ
to database, I got error that I have wrong type of typ
. In database type typ
column is string
.
Code that save to database
public override void save()
{
DialogResult dialogResult = MessageBox.Show("Czy napewno chcesz dodać obiekt?", "Powiadomienie", MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.Yes)
{
item.stan = "1";
komunikat.dodaj();
ATMAEntites.Przedstawiciele.Add(item);
ATMAEntites.SaveChanges();
load();
}
else if (dialogResult == DialogResult.No)
{
}
}
I think, that data type that i get in typ from ComboBoxItem is different that string, but when i try Convert to string, error is this same
public string typ
{
get
{
return item.typ.ToString();
}
set
{
if (value != item.typ)
{
item.typ = value;
OnPropertyChanged(() => typ);
}
}
}