简体   繁体   中英

Winforms DataGridView bound to List<T> - Show only specified properties of T

I have a DataGridView and I'm binding it directly to a generic List of a custom class, no BindingSource intermediary. This custom class has a number of public properties and I want my dataGridView to display only some of those properties.

I've created datagridview columns for the custom class properties I'm interested in, and set their DataPropertyName to the class properties names. But the gridview fetches all the properties from its source and displays them.

Is there anyway to display only those properties I'm interested in?

Use

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

in your class.

Yes, set AutoGenerateColumns = false, then manually populate columns. or use Browsable(false) attribute in columns which you don't want to show.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM