0

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?

namco
  • 6,208
  • 20
  • 59
  • 83
  • possible duplicate of [Is there an Attribute I can use in my class to tell DataGridView not to create a column for it when bound to a List](http://stackoverflow.com/questions/1066907/is-there-an-attribute-i-can-use-in-my-class-to-tell-datagridview-not-to-create-a) – Blorgbeard May 24 '13 at 08:01
  • You can set the Column's `DisplayIndex` after binding, but I don't think there's an attribute for it – Blorgbeard May 24 '13 at 08:15

2 Answers2

2

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; }
}
ducmami
  • 215
  • 1
  • 2
-1

This is probably what you are looking for http://msdn.microsoft.com/en-us/library/0c24a0d7.aspx

Liviu
  • 38
  • 9