PDA

View Full Version : Sleeper: Add ColumnHead to a ListBox via VBA



Kaizer
03-01-2007, 07:12 AM
I'm filling a ListBox via VBA code and would like to have this ListBox shows ColumnHeads descriptions. Is there a way to assign ColumnHeads names using VBA?

Bob Phillips
03-01-2007, 07:53 AM
The only way to get column heads is to set the RowSource to the part of the range excluding the heading, and set the ColumnHead property. Could be done in VBA, but you can't load it from elsewhere and get column heads.

Charlize
03-01-2007, 08:54 AM
Or you could use the extra listview control. With this control you can stipulate the columntext to be shown.

Charlize

Kaizer
03-01-2007, 09:46 AM
Or you could use the extra listview control. With this control you can stipulate the columntext to be shown.

Charlize

Can you give more details, please. I'm not sure I got it.

Charlize
03-03-2007, 01:12 PM
Take a look at this kb article http://vbaexpress.com/kb/getarticle.php?kb_id=916. When you still got some questions, you may ask them. This one deals with the columnheads (how to set them up) and filling the listviewlist with some data.

Charlize

JonPeltier
03-04-2007, 09:11 AM
I just use a regular listbox, and put labels on the userform above the listbox. It's much easier than dealing with nonstandard controls, and the labels don't scroll away when the listbox is scrolled.

I also often add functionality to the labels. I make them look more like a button, and when the user clicks on one, sort the data by that column. Pretty slick, they tell me.

Charlize
03-04-2007, 02:43 PM
Well, nice idea but I've had some problems with that scrolling. If your list is longer than the width that you can show, the working option for me was, at that time, a listview option. When your list is wider than the view of the box, when scrolling to the right, the columnheads also scroll. I believe that it's even possible to add that sorting thing with the listview.

Although I must admit that it will be a little bit easier to create something like that with the listbox thing and labels (looking like a button). Are labels scrollable ? So when you scroll to the right of a listbox that the labels scroll with the scrollbar ? Or can you say that a certain line must always be visible that acts as a columnhead ?

Charlize

JonPeltier
03-04-2007, 05:36 PM
I set up my listbox so it doesn't need to scroll sideways.

I don't think you can lock a header row in a listbox, but then I don't remember ever trying. It doesn't work if you fill the listbox using code, only if you use RowSource, and gaining headers is not enough of a reason to constrain my listbox and userform by using RowSource.