Show only selected headers in DataGridView

How can I display only the selected headers in the DataGridView control? For example, I have a DataTable with headers ("Name", "Age", "Status"), but when displaying, I would like to exclude the "Age" column.

Thanks!:)

+1


a source to share


2 answers


in DataBindingComplete () method:

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

      



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

0


a source


Personally, I will probably add the columns that I need manually ( AutoGenerateColumns=false

) instead of trying to subtract the ones I don't need.



If it was a class model (not DataTable

), you can do things like set [Browsable(false)]

properties that you never want to see. With DataTable

wonder, can not you do something with an unusual DataView

...
. Other than that, just add the columns you want.

+2


a source







All Articles