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
}

 

posted on 2022-06-20 23:18  hanzq_go  阅读(96)  评论(0编辑  收藏  举报

导航