更新时间:2023-02-15 21:02:01
恩是的,有的DisplayMember
和 ValueMember
在的CheckedListBox
性能>,虽然文档的 ValueMember
声称它的这一类不相关的
Well yes, there are DisplayMember
and ValueMember
properties on CheckedListBox
, although the docs for ValueMember
claim it's "not relevant to this class".
下面是呈现一个简单的例子的DisplayMember
工作:
Here's a quick example showing DisplayMember
working:
using System;
using System.Drawing;
using System.Windows.Forms;
class Test
{
static void Main()
{
CheckedListBox clb = new CheckedListBox {
DisplayMember = "Foo",
ValueMember = "Bar",
Items = {
new { Foo = "Hello", Bar = 10 },
new { Foo = "There", Bar = 20 }
}
};
Form f = new Form
{
Controls = { clb }
};
Application.Run(f);
}
}
另外请注意,该文档的状态:
Also note that the docs state:
您无法将数据绑定到的CheckedListBox。使用ComboBox或此列表框来代替。
有关更多信息,请参阅如何:绑定在Windows窗体ComboBox或ListBox控件数据
You cannot bind data to a CheckedListBox. Use a ComboBox or a ListBox for this instead. For more information, see How to: Bind a Windows Forms ComboBox or ListBox Control to Data.
由于上面的代码它的工作原理,想必在谈论更高级的数据绑定,使用数据源
?
Given the above code which works, presumably it's talking about more advanced data binding, using DataSource
?