在Windows窗体中将dictinary值绑定到Combox

时间:2017-03-16 11:42:14

标签: c#

是否可以将字典值绑定到Windows Combobox? 我只能为WPF应用程序找到好的解决方案

Dictionary<object,object>ProductInfo = new Dictionary<object, object>();

foreach (var data in p)
{
    ProductInfo.Add(data.PenType, data.PenColor);
    Console.WriteLine("{0} {1}", data.PenType,data.PenColor);
}

1 个答案:

答案 0 :(得分:1)

是的,您可以使用BindingSource Property

combobox1.DataSource = new BindingSource(ProductInfo,null); 
//ProductInfo is your dictionary
combobox1.ValueMember = "Key";
combobox1.DisplayMember= "Value";