关于Dictionary 数据绑定问题
有控件ComboBox需要绑定数据源Dictionary里面的数据,应该怎样做????
这是之前写的应急办法总感觉到不是很完美~想用数据绑定来实现~各位大侠指点一下咯
try
{
IDictionary<int, string> di = new Dictionary<int, string>();
di.Add(1, "zheng");
di.Add(2, "Liu");
di.Add(3, "Li");
IDictionary<object, object> ht = new Dictionary<object, object>();
foreach (KeyValuePair<int, string> kv in di)
{
ht.Add(this.comboBox1.Items.Add(kv.Value.ToString()), (int)kv.Key);
}
comboBox1.Tag = ht;
comboBox1.SelectedIndex = 0;
}
catch (Exception ex)
{
throw new Exception(ex.Message.ToString());
}