有“DisplayMember”和“ValueMember”像CheckedListBox控件的属性? C#winforms

我有这个DataTable具有以下结构:
ID | VALUE
----------------
1  | Item 1
2  | Item 2
3  | Item 3

并且通过将每行作为项目添加,我将DataTable中的值显示为CheckedListBox控件.

但是如何包含ID?
有“displayMember”和“ValueMember”像CheckedListBox控件的属性

解决方法

那么是的,CheckedListBox上有displayMember和ValueMember属性,尽管 ValueMember的文档声称它与这个类无关.

以下是显示displayMember工作的快速示例:

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);
    }
}

另请注意,文档状态:

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.

鉴于上述代码的作用,大概是使用DataSource来讨论更高级的数据绑定?

相关文章

本程序的编译和运行环境如下(如果有运行方面的问题欢迎在评...
水了一学期的院选修,万万没想到期末考试还有比较硬核的编程...
补充一下,先前文章末尾给出的下载链接的完整代码含有部分C&...
思路如标题所说采用模N取余法,难点是这个除法过程如何实现。...
本篇博客有更新!!!更新后效果图如下: 文章末尾的完整代码...
刚开始学习模块化程序设计时,估计大家都被形参和实参搞迷糊...