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;
            cbProvince.DataSource = bs;
            cbProvince.DisplayMember = "Key";
            cbProvince.ValueMember = "Value";
        }

        private void btnTest_Click(object sender, EventArgs e)
        {
            string s = cbProvince.Text;//显示值 广东省
            string s2 = cbProvince.SelectedValue.ToString();//实际值 http://mk.gd.soa.csg.cn
        }

评论