I have 2 forms (Main and Username).
My Main form has a mainMenu and a dropdown list (combobox) which displays usernames. The mainMenu allows an person to click the "Add User" menu item, which then displays my Username form, which is basically a simple input box, when the user clicks the Submit button on the Username form I want the username to be added to the cboUsers drop down box on the Main form...something like this.
Code:
In Username form
private void button1_Click(object sender, System.EventArgs e)
{
//Add the username to the Main forms Username dropdown list
Main.cboUsername.Items.Add(txtUsername.Text);
}
but obviously, it doesn't work that way...any ideas on how to get this to work?
That code will work fine as long as:
1. Main is the name of an instance of the form class, not the name of the actual class.
2. cboUsername is declared as a public member instead of private or protected.
Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.
you need to declare the username form slightly differently when showing it, here's a quick example i knocked up for you...
in main ( IE the first Form )...
main frmMain=(main)[Color=Blue]base[/COLOR].Owner;
frmMain.cboUsername.Items.Add(txtUserName.Text) ;
}
i'll include a zipped example to make it easier just incase
~ if a post is resolved, please mark it as [Resolved] protected string get_Signature(){return Censored;} [vbcode][php] please use code tags when posting any code [/php][/vbcode]