//前台绑定kcb_state private void addItems() { DataSet ds = new DataSet(); ds = this.sc.getItems(code,describe,tableName,strCondition); this.kcb_state.DataSource = ds.Tables[0]; this.kcb_state.DisplayMember = "describe"; //设置显示值 this.kcb_state.ValueMember = "code"; // 实际值 } //获取(getItems) public static DataSet getItems(string code,string describe,string tableName,string strCondition) { string sql = "select distinct "+code+" as code ,"+describe+" as describe from "+tableName+" where 1=1 "+strCondition; DB.DataHelper dtHelper = new DB.DataHelper(); return dtHelper.ExecuteSql(sql); }
Dictionary<int,string> dic = new Dictionary<int,string>(); dic.Add(1,"a"); dic.Add(2,"b"); foreach(var keyValue in dic) { this.combox.items.add(keyValue) } // 需要使用时 int index = ((Dictionary<int,string>)this.combox.SelectedItem).Key; string text = ((Dictionary<int,string>)this.combox.SelectedItem).Value;
private void ComboBox1_SelectedIndexChanged(object sender, EventArgs e) { this. ComboBox1.Items.AddRange(new object[] {"体制与管理","实验教学","仪器设备","实验队伍","环境与安全","管理规章制度"}); }
private void fuZhi() { DataSet ds = new DataSet(); ds = this.sc.GetItemsDescribe("ZT01"); this.kcb_state.DataSource = ds.Tables[0]; this.kcb_state.DisplayMember = "describe"; //设置显示值 this.kcb_state.ValueMember = "code_class"; // 实际值 }
//获取值得时候:
string state = "";
if(this.kcb_state.SelectedValue != null)
state = this.kcb_state.SelectedValue.ToString().Trim();