WinForms DataGridView 绑定到 List - 仅显示 T 的指定属性

本文关键字:显示 属性 绑定 DataGridView List WinForms | 更新日期: 2023-09-27 17:55:58

我有一个DataGridView,我直接将其绑定到自定义类的通用列表,没有BindingSource中介。此自定义类具有许多公共属性,我希望我的 dataGridView 仅显示其中一些属性。

我已经为我感兴趣的自定义类属性创建了 datagridview 列,并将其DataPropertyName设置为类属性名称。但是网格视图从其源中提取所有属性并显示它们。

无论如何,是否只显示我感兴趣的那些属性?

WinForms DataGridView 绑定到 List<T> - 仅显示 T 的指定属性

使用

[System.ComponentModel.Browsable(false)]
public int SomeProperty{get;set;}

在你的课堂上。

是的,设置自动生成列 = false,然后手动填充列。 或使用 Browsable(false)不想显示的列中的属性。