有"&的DisplayMember QUOT;和" ValueMember"像CheckedListBox控件属性? C#的WinForms [英] Is there "DisplayMember" and "ValueMember" like Properties for CheckedListBox control? C# winforms
问题描述
我有这样的数据表
结构如下:
ID | VALUE
----------------
1 | Item 1
2 | Item 2
3 | Item 3
和我显示从 DataTable中的值
进入加每一行作为一个项目一个的CheckedListBox
控制。
And I display the values from the DataTable
into a CheckedListBox
control by adding each row as an item.
但我怎么能包括ID?
是有的DisplayMember和ValueMember之类属性CheckedListBox控件?
But how can I include the ID? Is there "DisplayMember" and "ValueMember" like Properties for CheckedListBox control?
推荐答案
恩是的,有的DisplayMember
和 ValueMember
在的CheckedListBox
,虽然文档的< A HREF =http://msdn.microsoft.com/en-us/library/yx9dzztb%28v=VS.90%29.aspx> 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
?
这篇关于有"&的DisplayMember QUOT;和" ValueMember"像CheckedListBox控件属性? C#的WinForms的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!