简体   繁体   中英

How to hide DataGridView Column?

i have a simple class like below. And a List<Person> . I bind this list to the DataGridView in the Form.

class Person {
  public int ID {get; set;}
  public string Name { get; set; }
  public string Surname { get; set; }
  [DisplayName("Birth Date")]
  public DateTime BDate { get; set; }
}

With Attribute DisplayName i can change column header text.
My question is
Is there any Attribute to hide the ID Property of the Person ?

AND SECOND QUESTION (UPDATED)
Is there any Attribute to change the order of this properties when bind the list to the grid?

You can use: [Browsable(false)]

class Person {
  [Browsable(false)]
  public int ID {get; set;}
  public string Name { get; set; }
  public string Surname { get; set; }
  [DisplayName("Birth Date")]
  public DateTime BDate { get; set; }
}

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