views:

75

answers:

2

Hi! How can I display only selected headers in DataGridView control? For example I have DataTable with headers ("Name","Age","Status"), but I'd like to omit "Age" column when displaying.

Thanks! :)

A: 

in the DataBindingComplete() method:

this.dataGridView1.Columns["Age"].Visible = false;

ref: How to: Hide Columns in the Windows Forms DataGridView Control

Christian Hagelid
+2  A: 

Personally I'd probably add the columns that I do want manually (AutoGenerateColumns=false), rather than try to take away the ones I don't want.

If this was a class model (rather than DataTable) you can do things like setting [Browsable(false)] on properties you never want to see. With DataTable I wonder if you can't do something with a non-default DataView.... Other than that, you simply just Add the columns you want.

Marc Gravell