【发布时间】:2014-07-24 16:18:54
【问题描述】:
以下代码正在用值填充我的组合框
List<Filename> fnList = new List<Filename>();
fnList.Add(new Filename("test1.png"));
fnList.Add(new Filename("test2.png"));
fnList.Add(new Filename("test3.jpg"));
comboBox1.DataSource = fnList;
comboBox1.DisplayMember = "Name";
现在下面的代码应该将选定的值与关联对象中的成员同步。
comboBox1.DataBindings.Clear();
comboBox1.DataBindings.Add("SelectedValue", copy, "EventPicture");
copy 属于某个类,其中EventPicture 是字符串属性。这就是我希望每次用户更改组合框选择以及每次 EventPicture 值从代码的其他部分更改时同步选择值的地方。
此时我收到一个错误:
Cannot set the SelectedValue in a ListControl with an empty ValueMember.
【问题讨论】:
-
您是否尝试在组合框上设置
ValueMember? -
啊,这很快解决了问题,现在同步工作了 :) 我怎么能错过...