DataGridView 列绑定到字符串

发布于 2024-12-09 03:16:02 字数 323 浏览 0 评论 0原文

我在 WinForm 中有这样的定义:

private BindingList<String> rollbackLog = new BindingList<String>();

我有一个带有单个列的 DataGridView,我想将该列绑定到此列表。我遇到的问题是我不知道要为列的 DataPropertyName 属性分配什么。即,我不认为“string”的属性会返回值?

我是否必须使用字符串属性定义自己的类,然后从中读取?

考虑到我只有一个属性,使用 ListBox 将是首选选项,但这最终更出于兴趣。

I have this definition in a WinForm:

private BindingList<String> rollbackLog = new BindingList<String>();

I have a DataGridView with a single column and I want to bind that column to this list. The issue I have is I don't know what to assign to the DataPropertyName property of the column. ie, I don't think there's a property of "string" which will return the value?

Do I have to define my own class with a string property and then read from that?

Using a ListBox would be the preferred option given I have only a single property, but this is more out of interest in the end.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

任谁 2024-12-16 03:16:02

您可以使用一个简单的包装类

class Foo
{
    public string SomeProperty {get; set;}
}

,并使用

private BindingList<Foo> rollbackLog = new BindingList<Foo>();

并将 DataPropertyName 设置为 "SomeProperty"

You could use a simple wrapper class

class Foo
{
    public string SomeProperty {get; set;}
}

and use

private BindingList<Foo> rollbackLog = new BindingList<Foo>();

and set DataPropertyName to "SomeProperty" .

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文