Reputation: 43
I have a SQL Database where two tables have PK Relation. tblProject.contractorID is Foreign Key column and tblCompany.contractorID is Primary Key column.
I have created a Windows Form, marked tblProject.contractorID as ComboBox, marked tblProject as Details and drag and drop tblProject to the Form. Now, I have labels, textbox and combobox of the tblProject and a related binding navigator. (ihaleDataSet, tblProjectBindingSource, tblProjectTableAdapter, tableAdapterManager and tblProjectBindingNavigator)
When I run the project and click contractorID ComboBox, I want to Display tblCompany.shortName values. After selecting one of that values, I want to write tblCompany.contractorID value to tblProject.ContractorID and record accordingly.
I tried Data Binding Mode (DataSource= tblCompanyBindingSource, DisplayMember = "shortName", ValueMember = "companyID")
//
// contractorIDComboBox
//
this.contractorIDComboBox.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.tblProjectBindingSource, "contractorID", true));
this.contractorIDComboBox.DataSource = this.tblCompanyBindingSource;
this.contractorIDComboBox.DisplayMember = "shortName";
this.contractorIDComboBox.FormattingEnabled = true;
this.contractorIDComboBox.Location = new System.Drawing.Point(181, 100);
this.contractorIDComboBox.Name = "contractorIDComboBox";
this.contractorIDComboBox.Size = new System.Drawing.Size(121, 21);
this.contractorIDComboBox.TabIndex = 8;
this.contractorIDComboBox.ValueMember = "companyID";
It does not work. What shall I do to accomplish my aim?
Upvotes: 2
Views: 1787
Reputation: 43
I' ve solved the problem. Just replacing "Text" with "SelectedValue" in the first row is enough.
More information is here.
Upvotes: 1