Is there a way to set the heading of a listbox apart?

I’m using a listbox and the heading just looks like a regular row. It’s not bold or offset, or anything. Is there a way to do that?

It should not…

Have you set Listbox.HasHeading = True ?

Umm, well, Karen… no. Don’t know how the heck I forgot that. Sheesh! Thank you for the quick response!

Is there a way to set the properties of the heading separately? When I try to make the header bold, the row index of -1 returns an error.

You can set column alignment which will affect the header and set the CellAlignment for the cells differently whenever you add a row. That adds overhead but it may not matter that much. You can set the listbox as a whole to Bold (which will make all the headings bold) and then CellTextPaint to change the style of the cells… Or alternatively you could draw teh text in Cells anyway poi want in CellTextPaint.

Either way you could could create a listbox subclass that sets column header and cell style properties separately to automate it.

That said they should at least allow setting header alignment and front style (Plain, Bold italic) separately from the cells.

Another option If you don’t need resizable columns (it can be done gets more complicated i) you could also draw the headers yourself in the top visible row (Listbox.ScrollPosition tells you what row that is) in CellBackgroundPaint. Use CellBackgroundpaint so you can handle the case of a listbox with no rows added.

  • Karen

take a look at

this is a header class I wrote a while back that lets you take full control of the header

its a canvas that attaches to a listbox and responds to column resizes etc…

Set the text to the Header ?

Read teh related entries in the Language Reference (docs):
HasHeading: set it to True,
Heading: set the string to the appropriate columns Heading,
This entry have examples to set all Heading string at once (the infamous -1 trick) and set a specific column heading (Heading(Col#)).

You can change these values at will, all the time.

You can also let the user to change an individual Column Header string. I use Option-Click / Alt-Click to show a window that will let the user type a header string, OK and the clicked column text is changed.

In short, “Yes, you can” and here is most of the needed information.

And above this entry, you have other nice information to deal with the Heading.

At last: a simple search in the UserGuide-UserInterface.pdf file gaves entries for Heading in pages 75, 116 and 150 (161 talks about Web).

If all you want to do is make the Header Bold, but not the individual rows, set the whole ListBox to Bold, then in the CellTextPaint event add this line at the top:

g.Bold = False

For some other properties, you don’t have as much luck with workarounds such as this.