I have a problem with data binding in a drop down list. I have two classes:
A transaction has a Substrate attribute, and Transactions are stored in the Database. At the beginning of the program, I want to load all the transactions in a list and show them in a ListView. Each substrate capability should be shown in a combo box where the actual substrate is selected.
I tried 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 for
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 the entries in the list are displayed in the form of a list, and for each row all the possibilities of the substrate are in the combined list. But only for the first row of the ListView is the actual substrate selected.
source share