日期:2014-05-18 浏览次数:20778 次
DataTable dt = new DataTable(); dt.Columns.Add("DisplayValue"); dt.Columns.Add("Value"); DataRow dr = dt.NewRow(); dr["DisplayValue"] = "a"; dr["Value"] = "1"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["DisplayValue"] = "b"; dr["Value"] = "2"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["DisplayValue"] = "c"; dr["Value"] = "3"; dt.Rows.Add(dr); comboBox1.ValueMember = "Value"; comboBox1.DisplayMember = "DisplayValue"; comboBox1.DataSource = dt;
------解决方案--------------------
手动初始化:
string[] str = {"a","b","c"}; this.comboBox1.Items.AddRange(str); this.comboBox1.SelectedIndex = 0;
------解决方案--------------------