gpt4 book ai didi

c# - 使用 List<> 作为数据源隐藏 DataGridView 中的列?

转载 作者:太空狗 更新时间:2023-10-29 22:08:27 25 4
gpt4 key购买 nike

我有一个 List<>class X .

X有 3 列:a , bc .

现在我将列表绑定(bind)到 DataGridView 上:

dataGrid.DataSource = list;

如何只显示列 a 和 cGridView , 所以隐藏 Column b

如果可能,我不会编辑列表本身,也不会生成新列表。

这里有什么解决方案吗?

最佳答案

我假设你的类(class)是这样的:

private class MyClass
{
[DisplayName("Foo/Bar")]
public string FooBar { get; private set; }

[Browsable(false)]
public decimal Baz { get; private set; }

[DisplayName("Baz")]
public CurrencyBaz => string.Format(Baz, "C2");
}

在上面的代码中,gridview 的列名是这样的

  • 列名 1:("Foo/Bar")
  • 列名称 2:“Baz”
  • 列名称 3:“CurrencyBaz”

如果您不想显示该列,您可以添加此属性: [Browsable(false)]

上面代码中列名2没有显示......

希望对你有帮助...

关于c# - 使用 List<> 作为数据源隐藏 DataGridView 中的列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8054744/

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