动态绑定ComboBox 控件显示异常

狂舖 2019-10-07 09:29:00


如图,因工作需要,所以需要动态绑定ComboBox,代码已经写好。也可以实现对ComboBox控件的值绑定。但是奇怪的是运行后显示的页面异常,如图所示。不知道是怎么回事。请大牛给看看,给出改进建议,谢谢。
附代码如下:
ComboBox comboBoxCarPlateColor = new ComboBox();
var listCarPlateColor = new List<KeyValuePair<string, string>>();
for (int i = 0; i < familynames.Length; i++)
{
listCarPlateColor.Add(new KeyValuePair<string, string>(Convert.ToString(i+1), familynames[i]));
}
this.com_family.Items.Clear();//清空ComboBox
comboBoxCarPlateColor.DataSource = listCarPlateColor;
comboBoxCarPlateColor.ValueMember = "key";
comboBoxCarPlateColor.DisplayMember = "value";
comboBoxCarPlateColor.Parent = this;//加入这一句
//comboBoxCarPlateColor.SelectedValue = "2";
//this.Controls.Add(comboBoxCarPlateColor); //搜索的方法是这样的写的,实际运行会报错。所以用了下面的代码
this.com_family.Controls.Add(comboBoxCarPlateColor);//改进后的代码
...全文
31 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧