Hello,

I was wondering if you can supply me with information regarding the following. I have two forms - form A and form B. In form A I must choose two teams using two comboBoxes for each. When I click "Continue" which is a button - I want to be able to use whatever team is chosen in Form B... I can give you the following code that shows you what Ive tried but it does not work... ANY assistence regarding this matter will be much appreciated. :)

This is form A which I want to use in form B

        internal ComboBox cBox1 = new ComboBox();

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            //WHEN CHOOSING A TEAM THEIR FLAG WILL APPEAR IN THE PANEL

            if (comboBox1.SelectedIndex != comboBox2.SelectedIndex)
            {
                Graphics gR = panel1.CreateGraphics();
                comboBox1.SelectedItem = cBox1;

                if (cBox1.ToString() == "New Zealand")
                {
                    //DRAW NEW ZEALAND RUGBY LOGO
                    Image imag = Image.FromFile("NZ.jpg");
                    gR.DrawImage(imag, new Point(0, 0));
                    label6.Text = "No. 1";
                    //listOfTeams.Add(NZ);
                }
                else if (comboBox1.SelectedIndex == 1)
                {
                    //DRAW SOUTH AFRICA RUGBY LOGO
                    Image imag = Image.FromFile("SA.jpg");
                    gR.DrawImage(imag, new Point(0, 0));
                    label6.Text = "No. 2";

                    Team SA = new Team();
                    //listOfTeams.Add(SA);
                }
                else if (comboBox1.SelectedIndex == 2)
                {
                    //DRAW AUSTRALIA RUGBY LOGO
                    Image imag = Image.FromFile("AUS.jpg");
                    gR.DrawImage(imag, new Point(0, 0));
                    label6.Text = "No. 4";

                    Team AUS = new Team();
                    //listOfTeams.Add(AUS);
                }
                else if (comboBox1.SelectedIndex == 3)
                {
                    //DRAW ARGENTINIAN RUGBY LOGO
                    Image imag = Image.FromFile("ARG.png");
                    gR.DrawImage(imag, new Point(0, 0));
                    label6.Text = "No. 10";

                    Team ARG = new Team();
                    //listOfTeams.Add(ARG);
                }
            }
            else
            {
                //WHEN THE SAME TEAMS ARE SELECTED - PROMT USER TO SELECT/CHOOSE A DIFFERENT TEAM
                MessageBox.Show("Select a different team", "Team Selection",MessageBoxButtons.OK, MessageBoxIcon.Asterisk,MessageBoxDefaultButton.Button1);
                comboBox1.ResetText();
            }
        }

And this is form B where I want to use form A's comboBox selections

        internal PlayerList SCList = new PlayerList();

        int total = 0;
        int tryScored = 5;
        int penOrDropkick = 3;
        int conversionTry = 2;
        public int seconds;
        public int minutes;
        public int hours;

        public scoreCard()
        {
            InitializeComponent();
        }

        //LOADING THE FORM
        private void scoreCard_Load(object sender, EventArgs e)
        {
            FormA f = new FormB();

            Graphics gR = panel1.CreateGraphics(); 

            //IF THE COMBOBOX IN FORM A WAS INDEED "New Zealand" THEN IT WILL DRAW THE FLAG IN THE PANEL

            if(f.cBox1.ToString() == "New Zealand")
            {
                Image imag = Image.FromFile("AUS.jpg");
                gR.DrawImage(imag, new Point(0, 0));
            }
        }
    }

Thank you very much.

What is the code doing that is wrong?

One thing I've noticed, f is of type FormA but you're initializing it as a new FormB.

I would attempt approaching the problem by overloading the constructor on formB and have it take as parameters the values you need from FormA.

in essence:

public class formB

string name = "";

public formB (string n)

name = n;

then you would just instantiate a formB FROM formA with that overloaded definition...

// INSIDE formA

name = combobox1.getitemtext();

formB myformB = new formB (name); // This is the magic.

Hope that helps! cheers. (sorry had to take out some curlys...the code snippet verification drived me mad when writing this :P)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.