gpt4 book ai didi

c# - 为什么checkedlistbox没有数据源?如何绑定(bind)到值列表?

转载 作者:可可西里 更新时间:2023-11-01 07:52:38 24 4
gpt4 key购买 nike

我正在开发一个 Winform,我需要一个 checkedlistbox。我将值存储在一个具有 List 属性的对象中:

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

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

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

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

但是 myCheckedListBox 没有 DataSource 属性。

我是不是漏掉了什么?

最佳答案

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

不过,前一段时间我在一个项目上也遇到了同样的问题,并使用了this CodeProject article在我需要此功能的一个项目中编写解决方案。

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

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

编辑:上面的链接不再有效,但下面的摘录来自曾经存在于那里的文章。

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 中显示。

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

关于c# - 为什么checkedlistbox没有数据源?如何绑定(bind)到值列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8215933/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com