How to show only certain columns in a DataGridView with custom objects

后端 未结 8 1673
有刺的猬
有刺的猬 2020-12-29 07:18

I have a DataGridView and I need to add custom objects to it. Consider the following code:

DataGridView grid = new DataGridView();
grid.DataSource = objects         


        
8条回答
  •  情歌与酒
    2020-12-29 08:05

    The easiest is that you add the "System.ComponentModel.Browsable" attributes to your DataModel:

    public class TheDataModel 
    {
           [System.ComponentModel.Browsable(false)]
           public virtual int ID { get; protected set; }
           public virtual string FileName { get; set; }
           [System.ComponentModel.Browsable(false)]
           public virtual string ColumnNotShown1 { get; set; }
           [System.ComponentModel.Browsable(false)]
           public virtual string ColumnNotShown2  { get; set; }
    }
    

提交回复
热议问题