为什么checkedlistbox没有数据源?如何绑定到值列表? [英] How come checkedlistbox does not have datasource ? how to bind to a list of values?

查看:18
本文介绍了为什么checkedlistbox没有数据源?如何绑定到值列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 Winform,我需要一个检查列表框.我将值存储在具有 List 属性的对象中:

I am developing a Winform and I need a checkedlistbox. I have the values stored in an object which has a List property:

public static class Fields
{
    public static IList<string> FieldList { get; set; }

    static Fields()
    { ...//populate FieldList }
}

现在我希望我的 CheckedListBox 使用 Fields.FieldList 作为数据源.在网上搜索后我发现我需要设置

Now I would like my CheckedListBox to use Fields.FieldList as datasource. After searching online I found I needed to set

//in myForm_Load
mycheckedListBox.DataSource = Fields.FieldList;

但是 myCheckedListBox 没有 DataSource 属性.

But myCheckedListBox does not have a DataSource property.

我在这里遗漏了什么吗?

Am I missing something here?

推荐答案

根据文档,它应该有这个属性... http://msdn.microsoft.com/en-us/library/system.windows.forms.checkedlistbox.datasource(VS.90).aspx

Per the documentation, it should have this property... http://msdn.microsoft.com/en-us/library/system.windows.forms.checkedlistbox.datasource(VS.90).aspx

但是,不久前我在一个项目上也遇到了同样的问题,并使用了 thisCodeProject 文章,在我需要此功能的一个项目中编写解决方案.

However, I also had the same issue on a project a while back, and used this CodeProject article to code the solution in the one project where I needed this feature.

进一步研究,我确实发现了这个:

Researching a bit more, I did find this:

http://connect.microsoft.com/VisualStudio/feedback/details/115199/checkedlistbox-datasource-displaymember-valuemember-are-hidden

上面的链接不再有效,但下面的例外来自曾经驻留在那里的文章.

Microsoft 于 2005 年 5 月 30 日上午 10:28 发布
感谢您的反馈然而这是设计使然.我们不支持数据绑定CheckedListBox 控件.这些属性是从它基类继承的类并且无法删除,因此我们将它们隐藏在属性网格中,并且智能感知.

Posted by Microsoft on 5/30/2005 at 10:28 AM
Thanks for the feedback however this is by design. We do not support data binding on the CheckedListBox control. These properties are inherited from it base class and cannot be removed so we hid them form the property grid and IntelliSense.

这就解释了为什么该属性存在,但未在 Intellisense 中显示.

That explains why the property exists, but doesn't show in Intellisense.

这篇博文也值得一读:http://waxtadpole.wordpress.com/2009/10/12/assigning-custom-class-to-checkedlistbox-datasource/

这篇关于为什么checkedlistbox没有数据源?如何绑定到值列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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