Link to home
Start Free TrialLog in
Avatar of schnazzer
schnazzer

asked on

Passing data between forms

I'm trying my hand at creating a little sql server connection form.. most of which works except where I need to get the passed string back into the combo box on the first form...

here is what I've got.. I have a server select combo box on the first form that has one selection "<Browse for more options...>" that when selected, opens a child form.

on the child form, I have a tree view that when you select a child node and click the button, it should then repopulate the combo box on the parent form..

child form button code:
private void button1_Click(object sender, EventArgs e)
        {
            
            
            if (tabControlDatabaseServers.SelectedTab.Name == "tabPageLocalServers")
            {
                string sqlServerReturnValue = this.treeViewLocalDbServers.SelectedNode.ToString();
                parent.setServer(sqlServerReturnValue);
                this.Close();
            }
            else if (tabControlDatabaseServers.SelectedTab.Name == "tabPageNetworkServers")
            {
                string sqlServerReturnValue = this.treeViewNetworkDbServers.SelectedNode.ToString();
                parent.setServer(sqlServerReturnValue);
                this.Close();
            }
        }

Open in new window




here is the parent form partial code:
public void setServer(string sqlServerReturnValue)
        {
            this.comboBoxSqlServerSelect.Text = "";
            this.comboBoxSqlServerSelect.Text = sqlServerReturnValue;
            this.label3.Text = sqlServerReturnValue;
        }

        private void comboBoxSqlServerSelect_SelectedIndexChanged(object sender, EventArgs e)
        {
            // clear the combo box to prevent duplicates
            comboBoxSqlDbSelect.Items.Clear();
            comboBoxSqlDbSelect.Text = "";
            

            
            SqlConnectionStringBuilder connectionString = new SqlConnectionStringBuilder();
            connectionString.DataSource = comboBoxSqlServerSelect.Text.ToString();

            if (comboBoxSqlServerSelect.Text.ToString() == "<Browse for more options...>")
            {
                frmAdminSqlNetworkConnect sqlNetConn = new frmAdminSqlNetworkConnect(this);
                sqlNetConn.ShowDialog();
                
                
            }

Open in new window



What I get when I pass the value to a lable is "TreeNode: SERVERNAME"

but the combo box still contains "<Browse for more options...>"  when it should have just the server name I select..

I can't see where I've messed up..
Avatar of kaufmed
kaufmed
Flag of United States of America image

Avatar of schnazzer
schnazzer

ASKER

kaufmed,

I'm passing the data from the child form to the parent.. which is why I tested with a lable on the parent form.. where I'm having trouble is with the combo box.. when I select "<Browse for more options...>" as a selection in the combo box on the parent form, then the child opens, and I select a server from the treeview and click ok... back on the parent form the lable updates but the combo box doesn't...
ASKER CERTIFIED SOLUTION
Avatar of schnazzer
schnazzer

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
almost like searching for a typo.. fortunately I found it..