Populate a combo box with one data tabel and save the choice in another.
        Posted  
        
            by Scott Chamberlain
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Scott Chamberlain
        
        
        
        Published on 2010-05-03T15:23:34Z
        Indexed on 
            2010/05/04
            0:28 UTC
        
        
        Read the original article
        Hit count: 693
        
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";
        © Stack Overflow or respective owner