Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to prevent a multi line HeaderText in a DataGridView?

Tags:

When the length of the HeaderText property reaches a certain character limit and there is a space in the text, WinForms automatically inserts a link break in the header:

What I want:

+-----------------------+---
| Measurement Value (%) | ...
+-----------------------+---

What I get:

+-----------------------+---
| Measurement Value     | ...
|(%)                    |
+-----------------------+---

There is more than enough space to display all header cells without the lines breaks, but for whatever reason it is still inserted even when I set the AutoSizeMode to HeaderCell.

How can I prevent these line breaks, while still keeping the spaces in the HeaderText?

like image 555
xsl Avatar asked Feb 29 '12 22:02

xsl


2 Answers

The ColumnHeadersDefaultCellStyle property of the DataGridView has a boolean property called WrapMode. This is true by default. Make it false to set the required behaviour.

like image 167
PepitoSh Avatar answered Oct 28 '22 09:10

PepitoSh


You can not directly set it to false. The correct way of setting it to false is:

this.dataGridView1.ColumnHeadersDefaultCellStyle.WrapMode = DataGridViewTriState.False; 
like image 45
Sander Avatar answered Oct 28 '22 08:10

Sander