手动设置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
下一篇: 自定义标签(JSTL)