WPF: Problem with SelectedItem for ComboBox
Posted
by Anry
on Stack Overflow
See other posts from Stack Overflow
or by Anry
Published on 2010-05-24T17:57:05Z
Indexed on
2010/05/24
18:01 UTC
Read the original article
Hit count: 420
XAML:
<ComboBox Height="27" Margin="124,0,30,116" Name="cbProductDefaultVatRate" VerticalAlignment="Bottom" ItemsSource="{Binding}">
<ComboBox.ItemTemplate>
<DataTemplate>
<Label Height="26" Content="{Binding Path=Value}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
Set Data for cbProductDefaultVatRate.Items (Type - VatRate):
private void ShowAllVatRates()
{
cbProductDefaultVatRate.Items.Clear();
cbProductDefaultVatRate.ItemsSource = new VatRateRepository().GetAll();
}
Similarly, I defined property:
private Product SelectedProduct
{
get; set;
}
The Product contains VatRate:
SelectedProduct.DefaultVatRate
How to set SelectedItem equal SelectedProduct.DefaultVatRate? I tried:
cbProductDefaultVatRate.SelectedItem = SelectedProduct.DefaultVatRate;
But it does not work.
Thank you for answers!
© Stack Overflow or respective owner