其他分享
首页 > 其他分享> > Dictionary绑定到ComboBox显示值,实际值

Dictionary绑定到ComboBox显示值,实际值

作者:互联网

private void TestAndSetForm_Load(object sender, EventArgs e)
{
    Dictionary<string, string> dic = new Dictionary<string, string>();
    BindingSource bs = new BindingSource();
    dic["广东省"] = "http://mk.gd.soa.csg.cn";
    dic["云南省"] = "http://mk.yn.soa.csg.cn";
    dic["贵州省"] = "http://mk.gz.soa.csg.cn";
    dic["海南"] = "http://mk.hn.soa.csg.cn";
    dic["广西省"] = "http://mk.gx.soa.csg.cn";
     
    bs.DataSource = dic;
    comboBox1.DataSource = bs;
    comboBox1.DisplayMember = "Key";
    comboBox1.ValueMember = "Value";
}
 
private void btnTest_Click(object sender, EventArgs e)
{
    string s = comboBox1.Text;//显示值 广东省
    string s2 = comboBox1.SelectedValue.ToString();//实际值 http://mk.gd.soa.csg.cn
}

 

标签:soa,http,cn,Dictionary,ComboBox,csg,绑定,mk,dic
来源: https://www.cnblogs.com/hanzq/p/16395196.html