Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  HOME    TRACKER    Visual Basic

ListBox Column Headers

I know how to add columns headers (Icons and text) but, how can I add data under them. I use this:

with listbox1
.listitems.add , , "This is an Item", 1, 2
.listitems.add , , "This is another Item", 1, 2
end with

to add items to my listbox. Now, these go under the first column header, how can I make the code so there is some under the second and the third column header.


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Listbox Column Headers Name

I have a userform in Excel VBA which is connected to Access database.
there is a listbox in that userform and through SQL query I take the data from access table and add it to the listbox.
I know how to make it multi column listbox,currently I am using columncount property as 5 so there are 5 column.

the problem is that I don't know how to name the headers.
I know to use rowsource but I only can use it when data is from excel sheet. but in my case I need to get the data from access table.
can somebody please help how to get the headers name


Column Headers In Listbox
Hello People,

I have a listbox on a form which is called by the following:

VB Code:
Call Pg1aList(reclist)

Where reclist is the name of my Listbox and Pg1aList is this function:

VB Code:
Public Function Pg1aList(lstholder As ListBox)        On Error GoTo ErrHandler    Dim pg5 As ADODB.Recordset    'Dim strText1 As String     Set pg5 = MyConn.Execute("SELECT RecID, indname, datedeveloped FROM apprecords")    lstholder.Clear  With pg5    Do Until .EOF        lstholder.AddItem (pg5("indname"))        lstholder.ItemData(lstholder.NewIndex) = pg5("RecID")        .MoveNext    LoopEnd With      Exit Function    'error handlerErrHandler:    MsgBox Err.Description        pg5.Close    Set pg5 = Nothing    End Function

This works fine, but I would like to have the two column names that I am using brought into the top of the Listbox as well. I basically want Name and Date to appear at the top of the Listbox, and then all the necessary records.

Any ideas on how I do this...??

Any help would be appreciated,


Multi-Column ListBox Headers

I'm attempting to display a list of stuff using a multi column listbox on a UserForm.

I want each column to have a header, but **** man, I can't get them to display.

I can only find examples on the Internat where the RowSource property is pointed to a table of cells on a worksheet.

I want to set the column headers from within VBA.


How Do You Show Listbox Column Headers???
Hi everyone, I hope this is simple...

I have a listbox created from a file, which scrolls both vertically and horizontally.

I want to protect my column headers from being deleted, and set column headers to true in the properties, however, nothn happens, I get a blank column at top of listbox. I obviously need to something else here, but what is is it??? I am puzzled!

Get Column Headers
I read an XML into Excel, then I want to get the column headers into a string array. Check the pic for explanation


Column Headers
I have a VB6 app that returns data from a MySQL database to an Excel sheet. I can retrieve the data to Excel, but can't seem to get the column headings from the MySQL table to the Excel sheet. Can someone help me with this? Thanks.

Column Headers
Is there anyway to disable a column headers width from being adjusted during run time.


Column Headers
How can I change the caption on a column header on a bound datagrid control?


Column Headers
Please help
When I try to add column headers to my list box using
Dim clmx as ColumnHeader
I am receiving an error User defined type not defined.
If I change columnHeader to object on the add method i get method or data not found. I have check other examples of code and they are doing the same. Have i missed something in the properties box. I am using VB6. Also i am trying to add this in the Sub Form_Load()
thanks for any suggestions.

MSHFlexGrid Column Headers
I sure hope someone can help...

I am using an MSHFlexGrid, and the second band is displayed verically. I have the second band set to display column headers. However, after I rebind the grid with new data they are no longer there. I am running this after I rebind, but it still doesn't show:

Me.grdInvoice.ColHeader(1) = flexColHeaderOn

Any thoughts?

Column Headers In A ComboBox
VBA - Access

I have been working on a way to put all the headers from a Table called "Data" into a combobox. The column headers aways change so i cant just add them.

Ive been trying to write a SQL statement but i never did SQL in my studies. But i think it would be the best way to do it. So an examples on this would be great.


Listview Column Headers.
Hello All,

I'm haveing a problem with my listview object.

I onl need to have 5 columns shown on the list. However, no matter what I do there is always 6.

Anyway of changing this. I went to column headers & there is only 5 listed. Why do I keep getting six columns?


Listview: Fix Column Headers
How can I prevent the user resizing my listview columns?

Another question:
Can I set the style of a button, so that I get the look of: pushed in, when it is clicked on?

Thank you

Column Headers And Icons
Windows Explorer indicates the sort column/direction by an arrow icon placed after the columnheader. Selection of any particular header does not affect the alignment of that column.
I have searched previous posts, and have learned how to show or hide the icon in a listview control, but have not been able to place the icon after the columnheader. One of my columns has alignment lvwColumnRight. When the header is selected I show the icon, (on the left, because that is the best I can do), but I am unable to prevent the column reverting to alignment left.

Column Headers In Listboxes
how can i add column headers to my listboxes, just like in windows file explorer in the "details" view, is it a standard listbox or is it a special active x control?


MSFlexigrid Column Headers
Hello guys,

Hope you could help me with this one,,,how do i add column names on a msflexigrid?

Get Column Headers In Datagrid
Hi all!

I would like to ask if anyone knows how to get the names of the column
headers from a datagrid?
My grid is populated at run from an excel file. So the column names are not defined at design time.

Please help.

Column Headers In A MSFlexGrid
Does anyone know of a way to set up a MsFlexGrid's headers without using the FormatString Property?

Listview Column Headers
I am facing problem in Data alignment(right alingment) when I am adding icon in my Listview column headers. Can anybody tell me how can I fix data as right alingment if I use icon in Listview column header?


VB Flexgrid Column Headers
How do you add column headers (text) to the flexgrid control?

MSHFlexGrid Column Headers
I have an MSHFlexGrid filled via the code:
Set MSHFlexGrid1.DataSource = Adodc1
I want its column headers to be different from the field names of the Adodc1's Select statement. I want to accomplish that without using the As+Alias structure. Ex:
Adodc1.RecordSource = "Select LName From Customers"
Set MSHFlexGrid1.DataSource = Adodc1
Now, I want the column header of MSHFlexGrid1 to be Last Name, but without using:
Adodc1.RecordSource = "Select LName As [Last Name] From Customers"

DataGrid Column Headers

Is it possible to center a DataGrid's column header at runtime? I can center the values in the DataGrid's columns by using DataGrid1.Columns(i).Alignment = dbgCenter but I cannot figure out how to center the Column Header.

Thanks so much.


TreeVeiw & Column Headers
Can anyone tell me how to asign info under two different column headers in a list view using info from tree view

Column Headers In Listview
I am trying to wrapping the column header text in two lines but I couldn't. Can anybody tell me how can I wrap/show column headers full text in two lines?


Grouped Column Headers
Is there some way (API, subclass, ... ) to group two or more column headers in a (Visual Basic)ListView (Mscomctl.ocx v., like is MSFlexGrid ???

Rogério Weinert

MSHFlexGrid 2nd Band Column Headers
I have an MSHFlexGrid contol set up to display my bands of data vertically like this:

Parent Info
Child Info 1
Child Info 2
Child Info 3

Where my Parent Info is Band(0) and my Child Info's are Band(1). If I select the option of showing Column Headers for my Child Band it shows a header before every child record. Is there any way to have it show just once (before the first record)?

Hope someone can help...

Thank you!

How To Get Up Down Arrows On ListView Column Headers
By up down arrows I mean the little arrows that appear in the column headers to indicate whether the data is sorted by ascending or descending order. Anyone know how to have these appear?

Removing Column Headers In Listview
Hello all

I need some help with this,
I have found useful posts on this forum but couldn't find what I am looking for so if you know a post please guide me,
here is the problem:
I have a listview box that loads entries into the box a text file using the code below that I got from a post in the forum,

PHP Code:

Public Function load_listview(MyList As ListView, MyFile As String) 
    Dim line As String
    Dim mydata
    Dim row
    MyList.View = lvwReport
    Open MyFile For Input As #1
    mydata = Split(Input(LOF(1), 1), vbCrLf)
    Close #1
    'mydata = Split(line, ",")
    row = Split(mydata(0), ",")
    x = MyList.ColumnHeaders.Add(, , row(0))
    x = MyList.ColumnHeaders.Add(, , row(1))
    x = MyList.ColumnHeaders.Add(, , row(2))
    x = MyList.ColumnHeaders.Add(, , row(3))
    For i = 1 To UBound(mydata)
      row = Split(mydata(i), ",")
       x = MyList.ListItems.Add(, , row(0)).ListSubItems.Add(, , row(1))
       x = MyList.ListItems(i).ListSubItems.Add(, , row(2))
       x = MyList.ListItems(i).ListSubItems.Add(, , row(3))
    Next i
 End Function 

all works well, but it seems to load the column headers twice, I am not sure why, in my text file I have the column header titles only listed once!

I want to remove the duplication in the listview for the column headers,
How do I do that?
I know that


Will clear the items in the listview but how do I clear the column headers?

Thanks for reading

Adjust Column Headers Ina A Listview
Hi people
how can I do to lock the columns header of a listview, to don't allow the user change the width of each column

Flexgrid Column Headers/colors
Hey guys! I'm trying to learn how to use the flexgrid, and I have some questions about column headers and colors. First, is there a special column header feature, or are you just supposed to create your own headers? Second, what is the syntax for changing the background color of a specific row? Thanks for all the help.

Edit Column And Row Headers In FlexGrid
i'm using the EdFlexGrid very similar to MSFlexGrid and want users to be able to change the values in the greyed out column and row headers that are Greyed out. The only one I dont want them to be able to chane is the very top left header that isnt in any particular column or row. Thanks for your help

List View Column Headers
How do I change the colors of Listview column headers

Column Headers In List View

I am at present conducting search on my listview using finditem method, which works well on the first coulmn (text) better then the othercolumns (subitmes).

I wonder if it is possible to make the subitems as the first coloumn (text) so that I can conduct searches on that specific coloumn.

Does anyone know how to do this dynamically at run time?



Height Of Column Headers In A Listview
How do I control the height of a listview columnheader? This is my initializing code, and below is what comes out of it,
code, and the attached picture shows what it produces.
Private Sub InitListView2()
Dim lvw As Single

lvw = ListView2.Width

With ListView2.ColumnHeaders
.Add , "Name", "Name", lvw * 0.48
.Item("Name").Tag = LVTypeString
.Add , "Address", "Address", lvw * 0.48
End With

End Sub

Flexgrid Column Headers Blink
Hello, I have come across a weird problem. I have a form, that has a flexgrid on it. Data is received from a MySQL database...on windows 2000 computers, when the form opens, it almost appears that a key on the keyboard is stuck...and the column headers 'select' one at a time....then move to the next...and next...and next....and keeps doing this. However, on XP systems this doesnt happen. Below is my code:

Public Sub FillFlex2()
Dim i As Integer
On Error Resume Next

If rsMySQL2.RecordCount > 0 Then
Flex.Rows = rsMySQL2.RecordCount + 1
Flex.Cols = 6
Flex.FixedRows = 1
Debug.Print rsMySQL2.RecordCount
For i = 1 To rsMySQL2.RecordCount
Flex.TextMatrix(i, 0) = rsMySQL2.Fields("BarCode") & ""
Flex.TextMatrix(i, 1) = rsMySQL2.Fields("ItemCode") & ""
Flex.TextMatrix(i, 2) = rsMySQL2.Fields("ItemDesc") & ""
Flex.TextMatrix(i, 3) = rsMySQL2.Fields("LotNumber") & ""
Flex.TextMatrix(i, 4) = rsMySQL2.Fields("Pounds") & ""
If strFromForm = "frmShopFloor" Then
If rsMySQL2.Fields("Location") Like "*H1*" Then
Flex.TextMatrix(i, 5) = "Hopper 1"
ElseIf rsMySQL2.Fields("Location") Like "*H2*" Then
Flex.TextMatrix(i, 5) = "Hopper 2"
'Flex.TextMatrix(i, 5) = rsMySQL2.Fields("Location") & ""
Flex.TextMatrix(i, 5) = "Press: " & rsMySQL2.Fields("Location")
End If
Flex.TextMatrix(i, 5) = rsMySQL2.Fields("Location")
End If
Debug.Print i
AdjustGridColWidth Flex, lblCount, i, 0
AdjustGridColWidth Flex, lblCount, i, 1
AdjustGridColWidth Flex, lblCount, i, 2
AdjustGridColWidth Flex, lblCount, i, 3
AdjustGridColWidth Flex, lblCount, i, 4
AdjustGridColWidth Flex, lblCount, i, 5
Next i
Flex.Width = Flex.ColWidth(0) + Flex.ColWidth(1) + Flex.ColWidth(2) + Flex.ColWidth(3) + Flex.ColWidth(4) + Flex.ColWidth(5) + 100
'frmContents.Width = Flex.Width + 230
'lblCount.Width = frmContents.Width
Flex.ColAlignment(0) = flexAlignLeftCenter
Flex.ColAlignment(1) = flexAlignLeftCenter
Flex.ColAlignment(2) = flexAlignLeftCenter
Flex.ColAlignment(3) = flexAlignLeftCenter
Flex.ColAlignment(4) = flexAlignLeftCenter
Flex.ColAlignment(5) = flexAlignLeftCenter
End If
Flex.Width = Flex.ColWidth(0) + Flex.ColWidth(1) + Flex.ColWidth(2) + Flex.ColWidth(3) + Flex.ColWidth(4) + 100
frmContents.Width = Flex.Width + 230
lblCount.Width = frmContents.Width
If rsMySQL2.RecordCount > 1 Then
lblCount2.Caption = rsMySQL2.RecordCount & " materials found."
ElseIf rsMySQL2.RecordCount = 1 Then
lblCount2.Caption = rsMySQL2.RecordCount & " material found."
lblCount2.Caption = rsMySQL2.RecordCount & " materials found."
End If
End Sub

Public Sub AdjustGridColWidth(pobjGrid As MSFlexGrid, _
pobjLabel As Label, _
plngRow As Integer, _
plngCol As Integer)

' Adjusts the width of a flexgrid column, using the width required by a
' label using the same font, fontsize, and width. The label used must have
' Autosize = True and WordWrap = False.
' Also, the WordWrap property of the flexgrid must be set to True.

With pobjGrid
.Row = plngRow
.Col = plngCol
pobjLabel.FontName = .CellFontName
pobjLabel.FontSize = .CellFontSize
pobjLabel.Height = .RowHeight(.Row)
pobjLabel.Caption = .Text & " "
If pobjLabel.Width > .ColWidth(.Col) Then
.ColWidth(.Col) = pobjLabel.Width
End If
End With

End Sub

Listview - Lock Column Headers?
I have a listview in report view, how do you stop the moving of column width? So they are the size i set?

Export Column Headers To A CSV File
I am using this code:
Write #1, List1.ListItems(i).Text, List1.ListItems(i).ListSubItems(1).Text, _
List1.ListItems(i).ListSubItems(2).Text, List1.ListItems(i).ListSubItems(3).Text, _
List1.ListItems(i).ListSubItems(4).Text, List1.ListItems(i).ListSubItems(5).Text

It works, but there could be more than the 4 rows. Is there a way of exporting this according to the number of columns (each has to be seperated by a comma and has to be one command)?
Write x, y, z, ...

I can get the column headers into a temp var, but it copies all headers into a single cell (spreadsheet)

For i = 1 To List1.ColumnHeaders.Count
tmpHeaders = tmpHeaders & "," & List1.ColumnHeaders(i).Text
Next i


Menu's & Row/Column Headers In Excel

I want to remove the Row & Column headers when I open a particular Excel Workbook.

I know that I have to do any changes in the Procdure Workbook_Open, but what do I use?

Also I want to create a menu bar and then only show that, is there a way?


MSHFlexGrid & Changing Column Headers
I have MSHFlexGrid bound to a hierarchical recordset (defined via the standard DataEnvironment). What I want to do is change the column headings from their database column names to something a bit more readable. I have a function that queries a table containing the column name and a display name (GetFieldNameDesc). My thought was to loop through the column headers in the grid and replace the column name witht he display name. Here is the code:

'Update column headings
Dim S As String
Dim i As Integer
Dim n As Integer

i = MSHFlexGrid1.Cols - 1
n = 0
While n <= i
S = MSHFlexGrid1.ColHeaderCaption(0, n)
MSHFlexGrid1.ColHeaderCaption(0, n) = GetFieldNameDesc(S)
n = n + 1

Now, in debug, I can step through this code and it works fine. Checking the MSHFlexGrid1.ColHeaderCaption(0, n) after the reassignment seems to be fine. However once the form actually comes up, none of the new column headers are in place. I am doing this assignment routine at the tail end of the form load event.

My only thought on why this doesn't work is that it has something to do with this grid being bound to the hierarchical recordset, and maybe those column headers really aren't updateable.
Although, I have done this very same thing with a VSFlexGrid bound to a regular recordset.

ANy clues?

2-line Listview Column Headers?
I have some very long column names with very short data & would love to be able to have 2-line headers. Can this be done? (v4). Thanks.

MSFlexGrid Overwrites Column Headers?
Hi everyone. My first post - thanks for looking! I'm populating an MSFlexGrid with data from an access97 file. My code was created from the following example:

Private Sub Form_Load()
MSFlexGrid1.FormatString = "Artist Name |" & _
"Album Name | Tracks"

Data1.DatabaseName = App.Path & "CDCollection.mdb"

Data1.RecordSource = "select * from CDs order by ArtistName"
End Sub

The last line (Data1.RecordSource =) when run causes the FormatString property to be blown away. That is, the column headers are replaced with the database field names. Has anyone seen this before? The example seems simple enough but I just can't get it to work. I even thought there may be a problem with the version of my component and upgraded my VB but still have problem. I've tried setting the FormatString at the end, refreshing, still nothing...


Include Column Headers From ADO Recordset
I'm truly vexed. Here's my code to populate grid:

Public rsHandle As New ADODB.Recordset
Public strHandle As String

strHandle = "SELECT Results.*"
strHandle = strHandle & " From Results"
strHandle = strHandle & " WHERE (((Results.shipdate) Is Null));"

With rsHandle
Set .ActiveConnection = cnnCei
.CursorType = adOpenKeyset
.CursorLocation = adUseClient
.LockType = adLockOptimistic
.Open strHandle
End With

flxHandle.Rows = rsHandle.RecordCount + 1
flxHandle.Cols = rsHandle.Fields.Count + 1

For k = 0 To rsHandle.RecordCount - 1
For j = 1 To rsHandle.Fields.Count
If IsNull(rsHandle.Fields(j - 1)) Then flxHandle.TextMatrix(k, j) = ""
If rsHandle.Fields(j - 1) > 0 Then flxHandle.TextMatrix(k, j) = rsHandle(j - 1)
j = 1

So how about those column headers? Where are they?

How To Add Column Headers In Msforms Combobox

iam not able to add recordset field names to the column header of msforms.combobox.Pls help me

Thanks in advance


How Can I Make The Column Headers On My Grid?
when my grid was filled with the datas the size of the columns are the same and i wanted to make it depend on the length of the headers..

Hope some could help me with this..
Thanks in advance!

ListView - Information &amp; Column Headers

I Have a listView control with two headers. ID and Name. But i want to add the information e.g

listview1.listitems.add , , ID(1) & Name("Test")

Pleaase could someone help



Edited by - danielgraham on 4/12/2005 12:08:21 PM

Setting The MSHFlexGrid Column Headers
I am populating a MSHFlexGrid control using a linked ADO control. I select 'Retrieve Structure' and the MSHFlexGrid control is populated with the data in my Access database however the column headers are populated using the Access database column headers. Is there any way to change the column Headers to different headers as I don't want to use the headers in the Access database?? I tried using:

MSHFlexGrid1.colHeaderCaption(0,0) = "Customer Name"

However, it doesn't change the column name at run time.

Can anybody please advise if the column headers can be changed in code??


MSH Flexgrid Column Headers Bold
I always seem to come across the most peculiar problems while working in VBA. Unfortunately, I can't seem to find an answer for the latest problem.

I have a form with a hierarchical flexgrid which is populated by an ADODB recordset then fed to the mshflexgrid through the recordset property. My problem rises after I set the flexgrid recordset and it becomes populated, the column header (a fixed row) will not display the cellfontbold setting.

If I step through the code, the header is bold but when I run the code without breaking at any point the header is no longer bold. Not that the property isn't set, but that the flexgrid is not displaying it. If I print the .cellfontbold property it shows as being set to true, thus I'm out of ideas as to why it's not working correctly.

Everything else works fine except for the column header from bolding.

I'm using Access 2003 connected to a Pervasive database. The flexgrid properties in design are: allowbigselection =false; selectionmode= byrow; allowuserresizing = both; fillstyle = single;rows=0;columns=0;fixedrows=0; fixedcols = 0;scrollbars=both;highlight = always;columnheaders=false;everything else is default

Code:Dim rsSearch As ADODB.Recordset
Dim iSortColumn As Integer, sSortType As String
Private sub ProcessSearch()
        On Error Resume Next
        If rsSearch.State > 0 Then rsSearch.Close
        Set rsSearch = Nothing
        Set rsSearch = New ADODB.Recordset
        On Error GoTo 0
        rsSearch.CursorLocation = adUseClient
        rsSearch.Open "Select * From ""Order Master""", MyDatabase,adOpenDynamic, adLockReadOnly, adCmdText
        Set Me.flgrdOrderLookup.Recordset = rsSearch

        Me.flgrdOrderLookup.Rows = Me.flgrdOrderLookup.Recordset.RecordCount + 1
        Me.flgrdOrderLookup.FixedRows = 1

        SortByColumn iSortColumn
end sub

Private Sub flgrdOrderLookup_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Long, ByVal y As Long)
    If Me.flgrdOrderLookup.MouseRow <> 0 Then Exit Sub
    SortByColumn Me.flgrdOrderLookup.MouseCol
End Sub

Private Sub SortByColumn(ByVal Sort_Column As Integer)
    'Me.flgrdOrderLookup.Redraw = False
    If iSortColumn <> Sort_Column Then
        With Me.flgrdOrderLookup
            .Row = 0
            .Col = iSortColumn
            .CellFontBold = False
        End With
        sSortType = " ASC"
    ElseIf iSortColumn = Sort_Column Then
        If sSortType = " DESC" Then sSortType = " ASC" Else sSortType = " DESC"
        sSortType = " DESC"
    End If
    On Error Resume Next
    If Me.flgrdOrderLookup.Recordset.State > 0 Then
        Set Me.flgrdOrderLookup.Recordset = ""
        Set Me.flgrdOrderLookup.Recordset = rsSearch
        Me.flgrdOrderLookup.Recordset.Sort = ""
        Me.flgrdOrderLookup.Recordset.Sort = CStr(Chr(91) & Me.flgrdOrderLookup.TextMatrix(0, sort_column) & Chr(93) & sSortType)
    End If
    On Error GoTo 0

    iSortColumn = Sort_Column

    'Me.flgrdOrderLookup.Redraw = True
End Sub

Printing Out Datagrid Column Headers
Just wondering if there is any way to printout the Column Headers when i printout the rest of the Datagrid?


Public Sub GridPrint(gridQuery As DataGrid)
Dim I As Integer
Dim J As Integer
Dim PTab As Integer

For I = 0 To gridQuery.ApproxCount - 1
PTab = 20 'Set the first tab value
'This checks to see if a page break is needed

If Printer.CurrentY + Printer.TextHeight(gridQuery.Text) > Printer.ScaleHeight - 600 Then
End If

On Error Resume Next
gridQuery.Row = I 'Set the active row
On Error GoTo 0

For J = 0 To gridQuery.Columns.Count - 1
gridQuery.Col = J 'Set the current column

'Send the field to the print line and add the tab.
'Notice the semicolon at the end of the line.

Printer.Print Trim$(gridQuery.Text); Tab(PTab);

PTab = PTab + 20 'Increment the tab value

'After each column has printed to the print line

'a Printer.Print statement without a semicolon will
'will send the line to the printer and start a new
'Printer.Orientation = Landscape

End Sub

The above works fine but I need the Column Headers to print out too otherwise, the info means nothing to some users. Also, how do I set the printer to print in Landscape? I have tried:


Printer.Orientation = Landscape

But this doesn;t seem to work.

Thanks in advance

Moving ListView Column Headers
Is there a way that the user can move the Column headers of a list view control. Additionally a way to select the whole line rather than the first column.


Copyright © 2005-08, All rights reserved