ComboBox mit zwei Datenquellen
-
Hallo an alle,
ich möchte meiner ComboBox als List-Items eine Spalte aus einer SQL-Abfrage zuweisen und den ausgewählten Wert an eine Zelle in einer anderen SQL-Abfrage binden. Geht das und, wenn ja, wie?
Vielen Dank,
VRComputing
-
Mehr Infos. WinForms, WPF? Wie genau bindest du die Werte?
-
Windows Forms. Hier mein Code:
private FbConnection fbConnection; private FbDataAdapter fbDataAdapter = new FbDataAdapter(); private BindingSource bindingSourceAdressen = new BindingSource(); private BindingSource bindingSourceAdressenAnrede = new BindingSource(); private void Form1_Load(object sender, EventArgs e) { InitializeFirebirdConnection(); bindingSourceAdressen.DataSource = GetData("select * from tbladressen"); bindingSourceAdressenAnrede.DataSource = GetData("select * from tbladressenanrede"); bindingNavigator1.BindingSource = bindingSourceAdressen; // add data bindings to controls on form textBoxFirstName.DataBindings.Add(new Binding("Text", bindingSourceAdressen, "vorname")); textBoxLastName.DataBindings.Add(new Binding("Text", bindingSourceAdressen, "nachname")); comboBoxSalutation.DataBindings.Add(new Binding("Text", bindingSourceAdressen, "anrede")); comboBoxSalutation.DataSource = bindingSourceAdressenAnrede; comboBoxSalutation.DisplayMember = "anrede"; comboBoxSalutation.ValueMember = "anrede"; // register for firebird events FbRemoteEvent revent = new FbRemoteEvent(fbConnection); revent.AddEvents(new string[] { "new_address" }); revent.RemoteEventCounts += new FbRemoteEventEventHandler(FbEventCallback_NewAddress); revent.QueueEvents(); }
Die ListItems werden schon richtig angezeigt, aber wenn ich dann speichern will
private void buttonUpdate_Click(object sender, EventArgs e) { bindingSourceAdressen.EndEdit(); fbDataAdapter.Update((DataTable)bindingSourceAdressen.DataSource); }
bekomme ich eine "DB-Parallelitätsverletzung." - Exception.