且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

有"&的DisplayMember QUOT;和" ValueMember"像CheckedListBox控件属性? C#的WinForms

更新时间: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?