Thanks asawatzki, But unfortunately there are differences between VB 6.0 and VB.Net. I need a VB 6.0 example.
Main Topics
Browse All TopicsHow do I show column headers for a Visual Basic 6.0 project. Below is snippit of code that populates the listbox with the recordset. The column hearders do not have to come from the database as the field names in the database maybe obscure I can use simple English in the hearders. Also formatting is an issue. How do I get fields to line up as in a column like a datagrid? Is it possible to freeze the 1st column and allow the columns to scroll from left to right. Like that of datagrid when it is split. Can not use a datagrid because of "OCX" scurity issues.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Sorry it doesn't appear that this will work the way you want it to in VB6. The ListBox in VB6 does not allow for column headers and if you add columns to it then they are used for spillover and not for adding columns in the way you want.
For example if you change the columns property to 2 in the control properties for List1 and then add this code you'll see what I mean. It treats it like columns in a newspaper instead of columns in a spreadsheet:
For I = 0 To 300
List1.AddItem I
Next I
See this page http://www.daniweb.com/for
There is quite a difference in syntax from VB6 to VB.net. But as the Listbox object can not hold any columnheaders, so why not use a Listview instead?
I made you a sample project to demonstrate how you add columheaders and items in a listview
With ListView1
.View = lvwReport 'Must be report mode
.SortOrder = lvwAscending 'Ascending sort order
'Make columheaders
.ColumnHeaders.Add 1, "Name", "Name", .Width * 0.35 'width = 35% of total
.ColumnHeaders.Add 2, "Address", "Address", .Width * 0.25 'width = 25% of total
.ColumnHeaders.Add 3, "Zip", "Zip code", .Width * 0.15 'width = 15% of total
.ColumnHeaders.Add 4, "Phone", "Phone", .Width * 0.2 'width = 20% of total
End With
With ListView1
'Add names, 1st column
.ListItems.Add , , "John Doe"
.ListItems.Add , , "John Smith"
.ListItems.Add , , "Betsy Smith"
'Add addresses, 2nd column
.ListItems.Item(1).SubItem
.ListItems.Item(2).SubItem
.ListItems.Item(3).SubItem
'Add zip codes, 3rd column
.ListItems.Item(1).SubItem
.ListItems.Item(2).SubItem
.ListItems.Item(3).SubItem
'Add phone numbers, 4th column
.ListItems.Item(1).SubItem
.ListItems.Item(2).SubItem
.ListItems.Item(3).SubItem
End With
If you insist on going with ListBox, you may have to fake columnheaders by adding labels right above the ListBox, with the appropriate names, but it would be a drag to make it align properly.
Business Accounts
Answer for Membership
by: asawatzkiPosted on 2009-08-14 at 07:53:12ID: 25098650
I don't know about in VB6 but it can't be that different from VB.Net where it would be
Text = "Header1" der2", 10, HorizontalAlignment.Left)
ListView1.Columns.Item(0).
ListView1.Columns.Add("Hea
ListView1.Update
And then:
item = New ListViewItem("Test Column 1", 1)
item.SubItems.Add("Test Column 2")
ListView1.Items.Add(item)
For Each columnheader In ListView1.Columns
columnheader.Width = -2
Next
ListView1.Sorting = SortOrder.Ascending
ListView1.EndUpdate()
Hope this works or at least points you in the right direction.