views:

555

answers:

1

I'm trying to use the windows native (Theme-aware) header control to display just some column headers. The main purpose is to avoid manually drawing the column headers and rely on the natively supported functionality.

So the 2 options I was thinking of are:

(1) Use a HeaderControl, and add columns to it (I can't seem to find a header control supported by WinForms).

(2) Use a ListView Control, and tell it display no rows (or basically set its height to the height of the column header) - can't find any way to determine which height should I assign to the control.

Any good ideas much appreciated!

+2  A: 

There is no HeaderControl for WinForms in the .NET framework so far (the ListView utilises the ColumnHeader class but this is only useful with the ListView). If you are only targetting Microsoft Windows, you could look at wrapping the Win32 control for use in .NET although I expect that will be substantial work.

Your second option is a valid possibility even though it feels somewhat clunky. I can see difficulties arising in getting the list to size properly such that the header and only the header is visible.

A third option would be to roll your own HeaderButton that represents one column (like ColumnHeader) and use the theme drawing calls to draw it, then just combine them in a FlowLayoutPanel or TableLayoutPanel into your header bar. If you want resizing, you could make the HeaderButton have a grab region that you can pick up and alter its width.

I think the third option will be reasonably simple to create, even with the sizing ability, so I would recommend taking that route (I might even give it a go myself when I get home tonight).

Jeff Yates