有"&的DisplayMember QUOT;和" ValueMember"像CheckedListBox控件属性? C#的WinForms [英] Is there "DisplayMember" and "ValueMember" like Properties for CheckedListBox control? C# winforms

查看:119
本文介绍了有"&的DisplayMember QUOT;和" ValueMember"像CheckedListBox控件属性? 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 =htt​​p://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?

这篇关于有&QUOT;&的DisplayMember QUOT;和&QUOT; ValueMember&QUOT;像CheckedListBox控件属性? C#的WinForms的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆