Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I have ListBox Column Headers 1

Status
Not open for further replies.

JaeBrett

Programmer
May 5, 2003
196
CN
I am returning the results from a query in a Listbox. I need 7 Columns. Can I name them from within the ListBox?
 
No. Not with the standard list box control. You will want to use the ListView Control which is one of the Common Control component. Not sure which on off the top of my head.
 
The ListView is OK but if you only use Columns then I recommend using the FlexGrid as it is much faster and flexible for data layout.... it comes also with the VB setup.
 
Listview control is part of MSCOMCTL.OCX

There is also a listBox control in FM20.DLL which supports columns, which you can use but not distribute


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
If you do not need the checkbox style, the a DataGrid may be what you are looking for.

You can create a fabricated recordset to hold your data and bind it to the grid (also with the flex grid)
Then the searching, sorting, filtering, etc of the records will be much easier:

Dim rsADO as ADODB.Recordset
Set rsADO = New ADODB.Recordset

With rsADO
.Fields.Append "Field1", adVarWChar, 20, adFldUpdatable
.Fields.Append "Field2", adVarWChar, 10, adFldUpdatable
.Open
'you can now add the records in an array, or just use the traditional method with AddNew/Update
.AddNew Array("Field1", "Field2"), Array("Hi", "Bye")
'.AddNew
'.Fields("Field1").Value = "Hi"
'.Fields("Field1").Value = "Bye"
'.Update
End With

Set DataGrid1.DataSource = rsADO
'Set FlexGrid1.DataSource = rsADO
 
I think this is what you mean:

strSQL1 = "SELECT tblTempAdult.adLast & ', ' & tblTempAdult.adFirst AS AdultName, tblTempAdult.adBD AS Birthdate, tblTempAdult.adSx AS Sex, tblTempAdult.adCin AS CIN, tblTempAdult.adSS AS [SocialSecurity#], Nz(adPANum) AS [PA#]"
strSQL2 = " FROM tblTempAdult"
strSQL3 = " WHERE tblTempAdult.adCaseName = '" & Me.casName & "';"
strSQL4 = strSQL1 & strSQL2 & strSQL3

lstAdults.RowSource = strSQL4

This gives me headers--i set the row source from vba code.... obviously you have to change field & table names, etc.

Hope this helps..
 

A VB6 ListBox doesn't have a RowSource property, nor can you create multiple columns using multiple fields....

A DataList has a RowSource, but you also need to assign the ListField property, and this is a single field.

You would need to use the MS Office FM20 ListBox for a multiple column listbox as johnwm mentioned.
 
I ended up using a ListView and works perfect for what I need. Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top