加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

C#实现绑定Combobox的方法

发布时间:2020-12-15 05:43:24 所属栏目:百科 来源:网络整理
导读:本篇章节讲解C#实现绑定Combobox的方法。供大家参考研究。具体实现方法如下: public class StaticVariable{ public Dictionarystring,string tabTypeArray; public Dictionarystring,string transTimeArray; public Dictionarystring,string fileDe

本篇章节讲解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#程序设计有所帮助。

您可能感兴趣的文章:

  • C# ComboBox控件“设置 DataSource 属性后无法修改项集合”的完美解决方法
  • C#实现带搜索功能的ComboBox
  • C# 重写ComboBox实现下拉任意组件的方法
  • C# ComboBox的联动操作(三层架构)
  • C#实现ComboBox控件显示出多个数据源属性的方法
  • C#用ComboBox控件实现省与市的联动效果的方法
  • C#(WinForm) ComboBox和ListBox添加项及设置默认选择项
  • C# listview添加combobox到单元格的实现代码
  • c#构造ColorComboBox(颜色下拉框)
  • C#实现ComboBox自动匹配字符
  • C#中comboBox实现三级联动

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读