2013-03-19 48 views
0

我正在嘗試做一些我認爲會很簡單的事情,但目前完全讓我困惑。從DataGrid中的表中填充組合框

假設我有兩張桌子。一個擁有所有者列表(以保持唯一性)。另一個有物品清單和他們的主人。我想要有兩個數據網格: 1)所有者列表。 2)項目及其所有者列表,其中所有者是從組合框中挑選的。

其中的第一個很簡單:將表設置爲數據源,然後將其拖到WPF表單上。工作得很好:

<DataGrid ItemsSource="{Binding Source={StaticResource ownersViewSource}}" Name="ownersDataGrid" DataContext="{Binding}"> 
    <DataGrid.Columns> 
     <DataGridTextColumn x:Name="ownerColumn1" Binding="{Binding Path=Owner}" /> 
    </DataGrid.Columns> 
</DataGrid> 

其他部分不工作。我還以爲這會工作,但我顯然沒有得到它:

<DataGridTemplateColumn Header="Header"> 
    <DataGridTemplateColumn.CellTemplate> 
    <DataTemplate> 
     <ComboBox ItemsSource="{Binding Source={StaticResource ownersViewSource}}" DisplayMemberPath="Owner" /> 
    </DataTemplate> 
    </DataGridTemplateColumn.CellTemplate> 
</DataGridTemplateColumn> 

(很顯然,這是一個DataGrid中)

的問題是,這顯示列表 - 選擇,但來自組合框的項目也會將所有其他行中的選定項目更改爲該項目!

我哪裏錯了?

回答

0

Got it!

<DataGridComboBoxColumn Header="Owner Choice" ItemsSource="{Binding Source={StaticResource ownerViewSource}}" DisplayMemberPath="Owner" SelectedItemBinding="{Binding Path=Owner}" /> 

(的的ItemsSource結合一種的地方,SelectedItemBinding結合到另一個。)