combox填充

//前台绑定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();

 

转载于:https://www.cnblogs.com/quke123/p/4096634.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值