Using Column Headers with List Views

I'm trying to set up a very simple grid with columns and rows and have elected to use the List View control.

I want it more or less to resemble the List View found in Windows Explorer where you have column headers such as 'Modified', 'Size', 'Type' etc.

However, when I create a new column header with text 'Column 1' the rows appear but the column header does not appear at all - how do I make the column header appear, please?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Open the propety page of the list view by selecting the list on the form and right clicking on it and selecting the proprties meny.
Set the View proprty to lvwReport and use the column heared tab to insert the column headers.
At run time if you want to add the rows use the SubItems collections


The following example uses the Biblio.mdb database as a source to populate a ListView control with ListItem objects. To try this example, place a ListView control on a form and paste the code into the Declarations section. You must also be sure that the Biblio.mdb has been installed on your machine. In the code below, check the path in the OpenDatabase function and change it to reflect the actual path to Biblio.mdb on your machine.
Note   The example will not run unless you add a reference to the Microsoft DAO 3.5 Object Library. To do this, on the Project menu click References. Search for Microsoft DAO 3.5 Object Library and click the checkbox to select it.

Private Sub Form_Load()
      ' Add ColumnHeaders. The width of the columns is
      ' the width of the control divided by the number of
      ' ColumnHeader objects.
      ListView1.ColumnHeaders. _
      Add , , "Author", ListView1.Width / 3
      ListView1.ColumnHeaders. _
      Add , , "Author ID", ListView1.Width / 3, _
      ListView1.ColumnHeaders. _
      Add , , "Birthdate", ListView1.Width / 3
      ' Set View property to Report.
      ListView1.View = lvwReport

' Declare object variables for the
      ' Data Access objects.
      Dim myDb As Database, myRs As Recordset
      ' Set the Database to the BIBLIO.MDB database.
      ' IMPORTANT: the Biblio.mdb must be on your
      ' machine, and you must set the correct path to
      ' the file in the OpenDatabase function below.
      Set myDb =       DBEngine.Workspaces(0) _
            .OpenDatabase("c:\Program Files\VB\BIBLIO.MDB")
      ' Set the recordset to the "Authors" table.
      Set myRs = _
      myDb.OpenRecordset("Authors", dbOpenDynaset)

' Declare a variable to add ListItem objects.
      Dim itmX As ListItem

      ' While the record is not the last record,
      ' add a ListItem object. Use the author field for
      ' the ListItem object's text. Use the AuthorID
      ' field for the ListItem object's SubItem(1).
      ' Use the "Year of Birth" field for the ListItem
      ' object's SubItem(2).

      While Not myRs.EOF
            Set itmX = ListView1.ListItems. _
            Add(, , CStr(myRs!Author))      ' Author.

' If the AuthorID field is not null, then set
            ' SubItem 1 to it.
            If Not IsNull(myRs!Au_id) Then
                  itmX.SubItems(1) = CStr(myRs!Au_id)
            End If

            ' If the birth field is not Null, set
            ' SubItem 2 to it.
            If Not IsNull(myRs![Year Born]) Then
                  itmX.SubItems(2) = myRs![Year Born]
            End If
            myRs.MoveNext      ' Move to next record.
End Sub

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The answer is buried inside VBGuru's answer: the view MUST be lvwReport or else you never get to see any column headers.

There also is a HideColumnHeaders property that you can set to True if your list view is in lvwReport view and you do NOT want to see column headers.
gizzAuthor Commented:
Yes, it's the right clicking of the List View in design time that I didn't know about.
You can also set these properties at runtime:

YourListView.View = lvwReport

for example.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.