Hi i´ve got a problem with the databinding of a combobox in a listview. i have two classes: - Transaction - Substrate the Transaction has a attribute of the Substrate and the Transactiona are saved in a Datebase. At the start of the programm i want to load all Transactions as a list and show them in a ListView. Each possibility of Substrate should be shown in a Combobox, where the actual Substrate is selected.
i´ve tried it like this XAML
<ListView.View>
<GridView>
<GridViewColumn Header="Menge">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox Text="{Binding Path=Amount}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Substrate">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ComboBox
ItemsSource="{Binding ElementName=InternTransaction, Path=SubstrateList}"
DisplayMemberPath="Description"
SelectedValuePath="SubstrateID"
SelectedItem="{Binding Path=Substrate.SubstrateID}">
</ComboBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
code-behind
public partial class UCInternTransaction : UserControl
{
#region Attribute
private BsCBTTransactionController mTransactionController;
private ObservableCollection<BsCBTSubstrate> mSubstrateList;
#endregion
public UCInternTransaction()
{
InitializeComponent();
//Load Transactions
this.mTransactionController = WpfBioGas.Core.BsCAppFactory.getInstance().getCBTTransactionController();
this.mTransactionController.loadTransactions();
this.DataContext = this.mTransactionController.TransactionList;
loadData();
}
private void loadData()
{
//Load Substrate and bind to CBSubstrate
this.mSubstrateList = new ObservableCollection<BsCBTSubstrate>();
foreach (BsCBTSubstrate sub in WpfBioGas.Core.BsCAppFactory.getInstance().getBTFacade().BsBTSubstrate.loadAll())
{
this.mSubstrateList.Add(sub);
}
}
public ObservableCollection<BsCBTSubstrate> SubstrateList
{
get { return this.mSubstrateList; }
}
}
the problem is that all entries of the list are shown in the listview and for each row all possibilities of the Substrate are in the Combobox. But only for the first row of the Listview the actual Substrate is selected.