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..
C#

Avatar of undefined
Last Comment
schnazzer

8/22/2022 - Mon
kaufmed

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
schnazzer

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
schnazzer

ASKER
almost like searching for a typo.. fortunately I found it..
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes