日期:2014-05-17  浏览次数:20910 次

c# combox 下来框显示
     //从数据库获取要绑定到下拉框的数据
          DataTable dt =dsTables[0];
          if (dtList.Rows.Count == 0)
          {
              this.ComboBox.Items.Add(new System.Collections.DictionaryEntry("--无数据--", 0));
              //new System.Collections.DictionaryEntry("--无数据--", 0) --------->创建键值对
          }
          else//
          {
              this.ComboBox.Items.Add(new System.Collections.DictionaryEntry("--请选择--", 0));
              foreach (DataRow dr in dtList.Rows)
              {
                  this.ComboBox.Items.Add(new System.Collections.DictionaryEntry(dr["Title"].ToString(), int.Parse(dr["ID"].ToString())));//用取出数据创建值对
              }
          }
         
          this.ComboBox.DisplayMember = "key";//显示值
          this.ComboBox.ValueMember = "value";//数据值
          this.ComboBox.SelectedIndex = 0;//默认显示
      }