namco
namco

Reputation: 6338

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?

Upvotes: 0

Views: 184

Answers (2)

Liviu
Liviu

Reputation: 38

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

Upvotes: -1

ducmami
ducmami

Reputation: 215

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; }
}

Upvotes: 2

Related Questions