Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
So, what im trying to do is, if i have 2 or more comboboxes in C# and lets say each have 3 values in it (words) i want to add like if i select opcion 0 = 10 opction 1 = 5, option 2 = 0; same for combobox 2

and want to display answer in label

this is what i have so far...

C#
private void comboBox5_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (comboBox5.SelectedIndex)
            {
                case 0:
                    cntbth = 10;
                    break;
                case 1:
                    cntbth = 5;
                    break;
                case 2:
                    cntbth = 0;
                    break;
            }

            label13.Text = cntbth.ToString();
        }

        private void comboBox6_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (comboBox5.SelectedIndex)
            {
                case 0:
                    cntbth = 10;
                    break;
                case 1:
                    cntbth = 5;
                    break;
                case 2:
                    cntbth = 0;
                    break;
            }

            label13.Text = cntbth.ToString();
        }


cntbt is and INT (global) any suggestions?
Posted
Comments
Sergey Alexandrovich Kryukov 8-Jan-15 19:34pm    
ComboBox type? Which one? Full type name, please?
—SA
BillWoodruff 8-Jan-15 20:20pm    
Your code doesn't make sense: why would you ignore the value the user chose in comboBox6, and repeat setting the 'cntbth to the same value it has already been set to by the user's choice in comboBox5 ?

1 solution

 
Share this answer
 
Comments
azteca_04 9-Jan-15 16:01pm    
Tks for the replys and help, sorry for the delay been busy,

i try saving onto an array the result from each regular combobox and it does do the sum currectly only problem is that i have combobox to actomatacly start at index 0 but that would give me an automatic sum and i dont want that.

switch (comboBox5.SelectedIndex)
{
case 0:
cntbth[0] = 10;
break;
case 1:
cntbth[0] = 5;
break;
case 2:
cntbth[0] = 0;
break;
}

label13.Text = cntbth.Sum().ToString();

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900