2

I have a SQL Database where two tables have PK Relation. tblProject.contractorID is Foreign Key column and tblCompany.contractorID is Primary Key column.

sql

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)

2 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")

enter image description here

        // 
        // 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?

1
  • I' ve solved the problem. Just replacing "Text" with "SelectedValue" in the first row is enough. Commented Nov 15, 2013 at 8:43

1 Answer 1

1

I' ve solved the problem. Just replacing "Text" with "SelectedValue" in the first row is enough.

More information is here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.