欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

C#实现绑定Combobox的方法

程序员文章站 2023-11-25 15:34:22
本文实例讲述了c#实现绑定combobox的方法。分享给大家供大家参考。具体实现方法如下: public class staticvariable { p...

本文实例讲述了c#实现绑定combobox的方法。分享给大家供大家参考。具体实现方法如下:

public class staticvariable
{
  public dictionary<string, string> tabtypearray;
  public dictionary<string, string> transtimearray;
  public dictionary<string, string> filedealtypearray;
  public staticvariable()
  {
   tabtypearray = new dictionary<string, string>();  
   tabtypearray.add("1", "定长类型");
   tabtypearray.add("2", "非定长类型");
   tabtypearray.add("3", "手册压缩文件");
   tabtypearray.add("4", "dutyform");
   tabtypearray.add("10", "bulletin");
   tabtypearray.add("0", "未知类型");
   transtimearray = new dictionary<string, string>();
   transtimearray.add("-1", "实时处理");
   transtimearray.add("0", "不处理");
   filedealtypearray = new dictionary<string, string>();
   filedealtypearray.add("0", "普通文件");
   filedealtypearray.add("1", "增量文件");
  }
}
void bindercombobox()
{
 common.staticvariable staticvariable = new insetapplication.common.staticvariable();
 foreach (string key in staticvariable.tabtypearray.keys)
 {
  cbtabtype.items.add(new dictionaryentry(key, staticvariable.tabtypearray[key]));
 }
 foreach (string key in staticvariable.transtimearray.keys)
 {
  cbtranstime.items.add(new dictionaryentry(key, staticvariable.transtimearray[key]));
 }
 foreach (string key in staticvariable.filedealtypearray.keys)
 {
  cbdealtype.items.add(new dictionaryentry(key, staticvariable.filedealtypearray[key]));
 }
 cbdealtype.displaymember = "value";
 cbdealtype.valuemember = "key";
 cbtabtype.displaymember = "value";
 cbtabtype.valuemember = "key";
 cbtranstime.displaymember = "value";
 cbtranstime.valuemember = "key";
 if (cbtranstime.items.count > 0)
  cbtranstime.selectedindex = 0;
 if (cbdealtype.items.count > 0)
  cbdealtype.selectedindex = 0;
 if (cbtabtype.items.count > 0)
  cbtabtype.selectedindex = 0;
}

希望本文所述对大家的c#程序设计有所帮助。