This sample demonstrates how to display multiple layer column headers on the DataGridView contorl.
------------------------------------------------------------
| | January | February | March |
| | Win | Loss | Win | Loss | Win | Loss |
------------------------------------------------------------
|Team1 | | | | | | |
------------------------------------------------------------
|Team2 | | | | | | |
------------------------------------------------------------
|TeamN | | | | | | |
------------------------------------------------------------
-
Enable resizing on the column headers by setting the ColumnHeadersHeightSizeMode property as follows:
this.dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing;
-
Adjust the height for the column headers to make it wide enough for two layers:
this.dataGridView1.ColumnHeadersHeight = this.dataGridView1.ColumnHeadersHeight * 2;
-
Adjust the text alignment on the column headers to make the text display at the center of the bottom:
this.dataGridView1.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomCenter;
-
Handle the DataGridView.CellPainting event to draw text for each header cell.
-
Handle the DataGridView.Paint event to draw "merged" header cells.