以下是ComboBox绑定键值对的C#代码:

 ArrayList mylist = new ArrayList();
            mylist.Add(new DictionaryEntry("WinFormURL", "http://www.cnblogs.com/cate/winform/"));
            mylist.Add(new DictionaryEntry("ASPNETURL", "http://www.cnblogs.com/cate/aspnet/"));
            mylist.Add(new DictionaryEntry("JihuaURL", "http://www.cnblogs.com/jihua/"));
            comboBox1.DataSource = mylist;
            comboBox1.DisplayMember = "Value";
            comboBox1.ValueMember = "Key";

 

使用comboBox1.SelectedText获取所选项的值,

使用comboBox1.SelectedValue获取所选项的键

所获取键值 都是对象(object),根据需要可转换成其它类型,例如如string

 

ArrayList 需要引用命名空间 using System.Collections;

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-26
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案