2013-05-13 21 views
0

我有一個編輯客戶窗口。用戶輸入的所有字段都顯示在此窗口中。我也有一個性別字段,這是一個組合框。這個組合框的項目必須從表格t_Geslacht填充。表格t_Geslacht的ID和性別列已加入。在這個窗口中,用戶可以使用collectionview瀏覽記錄。當我將組合框綁定到性別表時,我會得到這些值。但是,當用戶瀏覽記錄時,該值不會改變。在combobox中填寫項目限制到collectionviewsource

這裏是我的組合框的XAML:

<ComboBox x:Name="geslachtComboBox1" Grid.Column="1" DisplayMemberPath="Geslacht" 
      HorizontalAlignment="Left" Height="22" 
      ItemsSource="{Binding Source={StaticResource lut_GeslachtViewSource}}" 
      SelectedValuePath="GeslachtID" Margin="10.2,5,0,5" Grid.Row="0" 
      VerticalAlignment="Center" Width="120"> 
    <ComboBox.ItemsPanel> 
     <ItemsPanelTemplate> 
     <VirtualizingStackPanel/> 
     </ItemsPanelTemplate> 
    </ComboBox.ItemsPanel> 
</ComboBox> 

下面是收集代碼:

customersViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("t_KlantenViewSource"))); 
System.Data.Objects.ObjectQuery<AOV.t_Klanten> customersQuery = this.Getlt_KlantenQuery(aoventities); 
customersViewSource.Source = customersQuery.Execute(System.Data.Objects.MergeOption.AppendOnly); 

我在做什麼錯?對不起,如果我沒有提供足夠的信息。

回答

0

您需要將組合框SelectedValue屬性綁定到Customer的「GenderID」屬性。

<ComboBox x:Name="geslachtComboBox1" Grid.Column="1" 
      DisplayMemberPath="Geslacht"  
      ItemsSource="{Binding Source={StaticResource lut_GeslachtViewSource}}" SelectedValuePath="GeslachtID" 
      SelectedValue="{Binding GenderID}"... //change to the property name for Gender in customer object.. 
+0

非常感謝你Jure!保存了我的一天。 – 2013-05-13 16:57:49