Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hidden certain column header in C# datagridview

for example if I want to make certain column header hidden in Datagridview. I'll use this code:

dataGridView1.ColumnHeadersVisible = false;

But this will make all the column header to be invisible. Now what if I want only certain column header to be hidden.

For instance I have 3 column header. I just want the 3rd column header to be invisible without hidden all the rows data belongs to that column. Is that possible?

Please advise and correct me if I'm wrong.

like image 257
Ren Avatar asked Dec 05 '25 20:12

Ren


1 Answers

You will need to handle the DataGridView.CellPainting Event.

In the event handler you will be given an instance of DataGridViewCellPaintingEventArgs. You can use the ColumnIndex and RowIndex properties of this object to determine if a header cell you want to hide is being painted. RowIndex will be -1 if the cell being painted is a column header.

It may just be a simple matter of doing nothing except e.Handled = true; when the header cell in question is being painted.

like image 81
Igby Largeman Avatar answered Dec 08 '25 11:12

Igby Largeman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!