C#中的下拉列表无法显示.text [英] Dropdownlist in C# cannot show .text

查看:128
本文介绍了C#中的下拉列表无法显示.text的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,全部,



我有2个下拉列表



combobox1和combobox2



当我在combobox1中选择一些东西时我想在我的代码中用combobox2显示一个数字。



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();
              }
          }
      }





我尝试过:



当它不是下拉列表时一切正常但现在eciindicator没有显示。有谁可以帮助我吗?



我尝试了几种方法,例如:



cmbeciindicator.items.insertat(0,this.eciindicator .toString());

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();

推荐答案

最有可能的是,你是将值转换为字符串:如果它是54之类的数字,那么ToString会将其转换为54 - 这与您要比较的054值不同。



所以从调试器开始,通过在<$ c上放置一个断点,确切地知道代码运行时 capturemethodtoeci 中的值是什么$ c>切换语句。逐步执行代码,您将看到发生了什么。
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.


这篇关于C#中的下拉列表无法显示.text的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆