OK .. for columns grab this .....
http://www.mvps.org/vbnet/code/listapi/cooltabs.htm and read this .....
http://www.mvps.org/vbnet/code/listapi/listboxtabs.htm
The listview isn't bad at all .. (not like the treeview - a horrid interface
to program).
With a listview, you declare a variable of type ListItem. You then set that
variable = the newly added item (aka the first column of data). You then use
the subitem() property of the variable to assign the values to the remaining
columns. IE ..
Private Sub Form_Load()
'create the columns ...
With ListView1
.ColumnHeaders.Add , , "Name"
.ColumnHeaders.Add , , "Age"
.ColumnHeaders.Add , , "Score"
.View = lvwReport
End With
End Sub
Private Sub Command1_Click()
'add the items
Dim itmx As ListItem
Set itmx = ListView1.ListItems.Add(, , "John Doe")
itmx.SubItems(1) = 30
itmx.SubItems(2) = 95
Set itmx = ListView1.ListItems.Add(, , "Fred Flintstone")
itmx.SubItems(1) = 45
itmx.SubItems(2) = 75
Set itmx = ListView1.ListItems.Add(, , "Bart Simpson")
itmx.SubItems(1) = 12
itmx.SubItems(2) = 86
End Sub
Private Sub ListView1_ColumnClick(ByVal ColumnHeader As
MSComctlLib.ColumnHeader)
'sort by column clicked
Static bOrder As Boolean
bOrder = Not bOrder
ListView1.SortKey = ColumnHeader.Index - 1
ListView1.SortOrder = Abs(bOrder)
ListView1.Sorted = True
End Sub
--
Randy Birch
MVP Visual Basic
http://www.mvps.org/vbnet/
Please respond only to the newsgroups so all can benefit.
Quote:
> Hello,
> Newbie question.
> I'm trying output some data into a listbox but it doesn't quite look
> like what I want. For example I'm outputting a string (name) that was
> read
> in from a file, followed by two byte type (age, score) variables. My
> output looks
> like this:
> John Doe 3095
> Fred Flintstone 4575
> Bart Simpson 1286
> I'm using the following code to produce the output:
> List1.AddItem person.name & person.age & person.score
> I would like to have the data displayed in columns. I defined the field
> "name" to be 20 chars
> in length and thought that the shorter names would be padded with spaces
> but it doesn't appear
> to be doing that. Is there a better way to do this or possibly another
> control I should be using?
> I'd really like to add column headings and have a more "professional"
> looking display. The ListView
> control looks cool but I think it might be overkill for what I want to
> do (not to mention more complex).
> Thanks