PC Review


Reply
Thread Tools Rate Thread

Adding Column Headings to a ListBox

 
 
Gr8lyConfused
Guest
Posts: n/a
 
      13th Nov 2009

I'm having a problem getting column headings to show up in a list box
control. I thought that, if the ColumnHeads property was set to True, the
first row of data would show up as column headings in the list box. This
column heading row would not be a selectable row. Here's a simple example
that illustrates my problem:

TestForm.TestListBox.Visible = True
TestForm.TestListBox.Clear
Dim n as Integer
For n = 1 To 10
If n = 1 Then
TestForm.TestListBox.AddItem
TestForm.TestListBox.List(n - 1, 0) = "Col 1"
TestForm.TestListBox.List(n - 1, 1) = "Col 2"
TestForm.TestListBox.List(n - 1, 2) = "Col 3"
End If
TestForm.TestListBox.AddItem
TestForm.TestListBox.List(n, 0) = n
TestForm.TestListBox.List(n, 1) = n + 1
TestForm.TestListBox.List(n, 2) = n + 2
Next n
TestForm.Show

The above section of code populates the list box ok, however, the list box
column heading row remains blank. The intended column headings (Col 1, Col 2
and Col 3) show up as the first selectable row in the list box which is not
what I want to do.

Any help would be greatly appreciated.

p.s. The source data for the list box is contained in specific columns for
a subset of rows in an existing spreadsheet.


 
Reply With Quote
 
 
 
 
LMH
Guest
Posts: n/a
 
      13th Nov 2009
See previous threads (search for 'ColumnHeads'). Doing the whole thing
programatically as you do in your example seems bound to fail (no pun
intended).

If as you say the required rows are in a spreadsheet, use Rowsource.
e.g. if data is in Range A2:C11 of Sheet1 put Sheet1!A2:C11 in the rowsource
property. Whatever is in Range A1:C1 will appear as the column headers.
--
LMH


"Gr8lyConfused" wrote:

>
> I'm having a problem getting column headings to show up in a list box
> control. I thought that, if the ColumnHeads property was set to True, the
> first row of data would show up as column headings in the list box. This
> column heading row would not be a selectable row. Here's a simple example
> that illustrates my problem:
>
> TestForm.TestListBox.Visible = True
> TestForm.TestListBox.Clear
> Dim n as Integer
> For n = 1 To 10
> If n = 1 Then
> TestForm.TestListBox.AddItem
> TestForm.TestListBox.List(n - 1, 0) = "Col 1"
> TestForm.TestListBox.List(n - 1, 1) = "Col 2"
> TestForm.TestListBox.List(n - 1, 2) = "Col 3"
> End If
> TestForm.TestListBox.AddItem
> TestForm.TestListBox.List(n, 0) = n
> TestForm.TestListBox.List(n, 1) = n + 1
> TestForm.TestListBox.List(n, 2) = n + 2
> Next n
> TestForm.Show
>
> The above section of code populates the list box ok, however, the list box
> column heading row remains blank. The intended column headings (Col 1, Col 2
> and Col 3) show up as the first selectable row in the list box which is not
> what I want to do.
>
> Any help would be greatly appreciated.
>
> p.s. The source data for the list box is contained in specific columns for
> a subset of rows in an existing spreadsheet.
>
>

 
Reply With Quote
 
Gr8lyConfused
Guest
Posts: n/a
 
      13th Nov 2009

Thanks for the reply LMH. The data in the list box is a significantly
smaller noncontiguous subset of all the rows and columns in the spreadsheet
(i.e. seem less than ideal for using the row source option.) I was able to
get the list populated with the items just fine but ran into the problem when
I thought I could easily add column headings to the list.

I did read through additional posts and found another post similar to mine.
It seems that the column heading options only work with Row Source and
ListFillRange methods that use ranges etc. Perhaps the list doesn't need
column headings.

Thanks again LMH.



"LMH" wrote:

> See previous threads (search for 'ColumnHeads'). Doing the whole thing
> programatically as you do in your example seems bound to fail (no pun
> intended).
>
> If as you say the required rows are in a spreadsheet, use Rowsource.
> e.g. if data is in Range A2:C11 of Sheet1 put Sheet1!A2:C11 in the rowsource
> property. Whatever is in Range A1:C1 will appear as the column headers.
> --
> LMH
>
>
> "Gr8lyConfused" wrote:
>
> >
> > I'm having a problem getting column headings to show up in a list box
> > control. I thought that, if the ColumnHeads property was set to True, the
> > first row of data would show up as column headings in the list box. This
> > column heading row would not be a selectable row. Here's a simple example
> > that illustrates my problem:
> >
> > TestForm.TestListBox.Visible = True
> > TestForm.TestListBox.Clear
> > Dim n as Integer
> > For n = 1 To 10
> > If n = 1 Then
> > TestForm.TestListBox.AddItem
> > TestForm.TestListBox.List(n - 1, 0) = "Col 1"
> > TestForm.TestListBox.List(n - 1, 1) = "Col 2"
> > TestForm.TestListBox.List(n - 1, 2) = "Col 3"
> > End If
> > TestForm.TestListBox.AddItem
> > TestForm.TestListBox.List(n, 0) = n
> > TestForm.TestListBox.List(n, 1) = n + 1
> > TestForm.TestListBox.List(n, 2) = n + 2
> > Next n
> > TestForm.Show
> >
> > The above section of code populates the list box ok, however, the list box
> > column heading row remains blank. The intended column headings (Col 1, Col 2
> > and Col 3) show up as the first selectable row in the list box which is not
> > what I want to do.
> >
> > Any help would be greatly appreciated.
> >
> > p.s. The source data for the list box is contained in specific columns for
> > a subset of rows in an existing spreadsheet.
> >
> >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding a new column to ListBox! Bob V Microsoft Access 7 18th Nov 2007 04:07 AM
column headings in a listbox cd Microsoft Excel Discussion 1 30th Nov 2005 08:45 PM
Listbox column headings BT Microsoft Excel Programming 3 30th Dec 2004 09:08 PM
Column Headings on a Listbox? RockNRoll Microsoft Access Forms 5 28th Jul 2004 07:41 PM
Re: Keydown event in listbox with column headings Stephen Lebans Microsoft Access Form Coding 0 28th May 2004 01:39 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:31 AM.