欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

手动设置combox的选项(key/value)

程序员文章站 2022-03-04 11:49:44
...
List<KeyValuePair<string, string>> listItem = new List<KeyValuePair<string, string>>();
listItem.Add(new KeyValuePair<string, string>("苹果", "Apple"));
combox.DisplayMember = "Key";
combox.ValueMember = "Value";
combox.DataSource = listItem;

如果key是int:

List<KeyValuePair<string, int>> listItem = new List<KeyValuePair<string, int>>();
listItem.Add(new KeyValuePair<string, int>("苹果", 1));
combox.DisplayMember = "Key";
combox.ValueMember = "Value";
combox.DataSource = listItem;

参考自: https://blog.csdn.net/kankankankan2222/article/details/8330650

相关标签: Winform