views:

78

answers:

1

Hi Folks,

I have a little Problem. A SP give me a several list of URL´s. The Urls are binded on a Combobox. When i Select an Item, always the Object comes to the Combobox not the Selected Value, see the code below:

<DataTemplate x:Key="Webadressen" DataType="{x:Type src2:GetWebadressenResult}" >
<StackPanel>
    <Label Content="{Binding Path=Adresse}" />
</StackPanel>
</DataTemplate>

<ComboBox Width="192" IsEditable="True" Margin="2" Name="Cbox_GDWeb" ItemTemplate="{StaticResource Webadressen}" SelectionChanged="Cbox_GDWeb_SelectionChanged">

 private void Cbox_GDWeb_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
      GetWebadressenResult test = (GetWebadressenResult)this.Cbox_GDWeb.SelectedValue;
      MessageBox.Show(test.Adresse.ToString());
      this.Cbox_GDWeb.Text = test.Adresse.ToString(); /* Not Working cause the this Event calls the same Method */
 }
A: 

Change your ComboBox to this

<ComboBox Width="192" IsEditable="True" Margin="2" Name="Cbox_GDWeb" DisplayMemberPath="Adresse" SelectedValuePath="Adresse" SelectedValue="{Binding Path=Adresse}">

then you wont need the Datatemplate and it will work fine

you also wont need the SelectionChange event to change your selecteditem

Mark