Click to See Complete Forum and Search --> : Divider in a listbox


jasiu
October 23rd, 2001, 08:13 PM
Hello

I am looking for a divder in a listbox control or something, I wish to have the same look as in Filemanager in win9x where you can move the display area of files, dates and such.

What control does that and how do I use it ?

tia

Cakkie
October 24th, 2001, 01:36 AM
You can use the listview control for that. This can be found in the Windows Common Controls. You will need to set the display to report, and add columns to the control (using custom in the property window). Once you've done that, you will need to add ListItems to the list.

private Sub Command1_Click()

Dim LI as ListItem
Dim T as Integer

ListView1.ListItems.Clear
for T=1 to 10
set LI = ListView1.ListItems.Add Text:="Item " & T
LI.SubItems(1) = "Item " & T & " Col 2"
LI.SubItems(2) = "Item " & T & " Col 3"
next T

End Sub




Tom Cannaerts
slisse@planetinternet.be

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook

John G Duffy
October 24th, 2001, 12:49 PM
Here is a simple example of a Listview with three columns. It also supports sorting of those columns.
Start a new project. Add a Listview (name it lv)
Paste this code into the general declarations section of the form and run the program.
The Form_Load event will setup and populate the listview. Click on column headers to Sort it.

option Explicit

public Function GetRandomNumber()
Randomize
GetRandomNumber = Int((99999 - 1 + 1) * Rnd + 1)
End Function

private Sub Form_Load()
Dim NX as ListItem, i as Integer
Dim Temp as string
lv.ListItems.Clear
lv.ColumnHeaders.Clear
lv.ColumnHeaders.Add , "Col1", "Item", 500, lvwColumnLeft
lv.ColumnHeaders.Add , "string", "string", 3000, lvwColumnRight
lv.ColumnHeaders.Add , "Number", "Number", 2000, lvwColumnRight
lv.View = lvwReport
for i = 0 to 100
Temp = string(25, " ")
RSet Temp = Format(GetRandomNumber, "###,###,###.#0")
set NX = lv.ListItems.Add(, "A" & Chr(i), i)
NX.SubItems(1) = GetRandomNumber
NX.SubItems(2) = Temp
next i

End Sub

private Sub lv_ColumnClick(byval ColumnHeader as MSComctlLib.ColumnHeader)
lv.SortKey = ColumnHeader.Index - 1
If lv.SortOrder = 0 then
lv.SortOrder = 1
else
lv.SortOrder = 0
End If
' set Sorted to true to sort the list.
lv.Sorted = true ' force list sort

End Sub




John G