Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, all,

I have 2 dropdown list

combobox1 and combobox2

when I will choose something in combobox1 I want to show a number in combobox2 this what I did in my code.

private void cmbCaptureMethod_SelectedIndexChanged(object sender, EventArgs e)
      {
          ComboBox senderComboBox = (ComboBox)sender;

          if (senderComboBox.SelectedIndex > 0)
          {
              if (this.Institution_number == "00000004" && this.Card_type == "Visa Card")
              {
                  string capturemethodtoeci = cmbCaptureMethod.SelectedValue.ToString();

                  switch (capturemethodtoeci)
                  {
                      case "030":
                          this.eciindicator = 1;
                          break;
                      case "045":
                          this.eciindicator = 2;
                          break;
                      case "050":
                          this.eciindicator = 5;
                          break;
                      case "051":
                          this.eciindicator = 6;
                          break;
                      case "053":
                          this.eciindicator = 8;
                          break;
                      case "054":
                          this.eciindicator = 7;
                          break;
                      case "121":
                          this.eciindicator = 0;
                          break;
                      default:
                          break;
                  }
                  cmbEciIndicator.Text = this.eciindicator.ToString();
              }
          }
      }


What I have tried:

when it was not dropdownlist everything works perfectly but now the eciindicator is not showing. Can someone help me please?

I have tried several methods like :

cmbeciindicator.items.insertat(0,this.eciindicator.toString());
cmbeciindicator.text = this.eciindicator.toString();
Posted
Updated 19-Sep-17 21:34pm

1 solution

Most likely, it's that you are converting a value to a string: if it's a number like 54, then ToString will convert it to "54" - which is not the same value as the "054" you are comparing against.

So start with the debugger, and find out exactly what the value in capturemethodtoeci actually is when the code is running by putting a breakpoint on the switch statement. Step through the code, and you'll see what is happening.
 
Share this answer
 
Comments
Joe Doe234 20-Sep-17 3:39am    
yes, i did that and it is working right. The problem is when I changed the combo box to dropdownlist from standard. when it was standard everything works well.

maybe I need to use something else to show it. PS: the cmbeciindicator will be disabled . sorry if I do not mention it.

and the capturemethodtoeci is string not integers that why it is working i think.

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