将字符串集合绑定到 ListView、Windows 窗体
我有一个 StringCollection,我想以一种方式绑定到 ListView。如图所示,ListView 应显示 StringCollection 的内容。我将以编程方式从集合中删除项目,这样它们就不需要通过 ListView 与之交互。
我有一个带有属性的表单,就像这样 -->
public DRIUploadForm()
{
InitializeComponent();
lvwDRIClients.DataBindings.Add("Items", this.DirtyDRIClients, "DirtyDRIClients");
}
private StringCollection _DirtyDRIClients;
public StringCollection DirtyDRIClients
{
get
{
return _DirtyDRIClients;
}
set
{
_DirtyDRIClients = Settings.Default.DRIUpdates;
}
}
I have a StringCollection that I want to One Way Bind to a ListView. As in, the ListView should display the contents of the StringCollection. I will be removing items from the collection programatically so they don't need to interact with it through the ListView.
I have a Form with a Property, like so -->
public DRIUploadForm()
{
InitializeComponent();
lvwDRIClients.DataBindings.Add("Items", this.DirtyDRIClients, "DirtyDRIClients");
}
private StringCollection _DirtyDRIClients;
public StringCollection DirtyDRIClients
{
get
{
return _DirtyDRIClients;
}
set
{
_DirtyDRIClients = Settings.Default.DRIUpdates;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您实际上无法绑定到 ListView 控件,因为它不支持绑定。您需要以编程方式添加项目。但是,您可以绑定到 ListBox,尽管正如其他人所说,您不能直接绑定字符串,您需要为它们创建一个包装器。像这样的东西...
You cannot actually bind to a ListView control, as it does not support binding. You need to add the items programmatically. You can however bind to a ListBox, although as others have said you cannot bind strings directly, you need to create a wrapper for them. Something like this...