UnhandledExcepSean
UnhandledExcepSean

Reputation: 12804

Multiline column headers in .NET4 WinForm Listview

I have a listview in Details view and I have added columns. I would like to have the column header increase in height and either word-wrap the header text or allow me to specify the line break using a CrLf.

Is this possible using the standard .NET controls?

Upvotes: 2

Views: 3962

Answers (2)

Libor
Libor

Reputation: 3303

Better ListView control does just this and it is written pure managed (.NET) code.

Both column headers and items (and even group headers) can contain arbitrary multi-line text, even with custom line breaks. Maximum number of lines can be limited by a property:

enter image description here

enter image description here

Upvotes: -1

Hans Passant
Hans Passant

Reputation: 941407

That's difficult, you cannot control the column header height directly. You can do it indirectly by giving the ListView a big Font. You then need to set the OwnerDraw property to true and implement the DrawItem, DrawSubItem and DrawColumnHeader events. The latter lets you word-wrap the text. You will also need to set the Font property for each ListViewItem you add so they are not drawn large as well. Unpleasant but not impossible.

Upvotes: 3

Related Questions