Populate a combo box with one data tabel and save the choice in another.
- by Scott Chamberlain
I have two data tables in a data set for example lets say
Servers:
| Server | Ip |
Users:
| Username | Password | Server |
and there is a foreign key on users that points to servers.
How do I make a combo box that list all of the servers. Then how do I make the selected server in that combo box be saved in the data set in the Server column of the users table.
EDIT --
I havent tested it yet but is this the right way?
this.bsServers.DataMember = "Servers";
this.bsServers.DataSource = this.dataSet;
this.bsUsers.DataMember = "FK_Users_Servers";
this.bsUsers.DataSource = this.bsServers;
this.serverComboBox.DataBindings.Add(new System.Windows.Forms.Binding("SelectedValue", this.bsUsers, "Server", true));
this.serverComboBox.DataSource = this.bsServers;
this.serverComboBox.DisplayMember = "Server";
this.serverComboBox.ValueMember = "Server";