ListBox.AddFolder

From Real Software Documentation

Jump to: navigation, search
Method
ListBox.AddFolder ( Item as String )

Appends Item in a new row to the end of the list and adds disclosure triangle only if the Hierarchical property is set to True.

For multi-column ListBoxes, Item is always assigned to column zero. In the case of hierarchical ListBoxes, AddFolder appends Item to the subitems of the expanded row when called in the ExpandRow event.

Examples

The following example adds creates a hierarchical ListBox. Note that AddFolder must be called to create the hierarchical relationship.

Dim i, u as Integer
Dim s1,sub1 as string
Me.columnwidths="150,0"
s1="Michigan,Ohio,Minnesota"
sub1="Grand Blanc,Bad Axe,Flint,Benton Harbor,"_
+"Detroit;Cleveland,Columbus,Akron,Pleasantville;St. Paul,Frostbite Falls"
u=CountFields(s1,",")
For i=1 to u
If NthField(sub1,";",i)<> "" then
Me.addfolder ""
Me.cell(i-1,1)=NthField(sub1,";",i)
end if
Me.cell(i-1,0)=NthField(s1,",",i)
Next
Me.ColumnCount=1

See the section “Hierarchical Listboxes” in the Notes section for illustrations of the ListBox in expanded and collapsed states.

Volume Browser Example

The “Volume Browser” example project in the Examples folder that ships with Real Studio is a file browser that displays the file structure of the user's hard disks as a hierarchical listbox. Is uses a custom class based on the ListBox. The Open event of the custom class builds the hierarchical list using AddFolder in a For loop for all of the user’s mounted volumes. The code for the Open event is this:

dim i as integer
dim f as folderitem
columnCount=4
PathColumn=ColumnCount+1
columnwidths="55%,20%,15%,10%"
for i=0 to VolumeCount-1
f=Volume(i)
addfolder f.name
RowPicture(listcount-1) = app.ResourceFork.getcicn(777)
cell(i,PathColumn)=f.absolutepath
next


The ExpandRow event uses AddRow to display nested folders and files in the directory. Again, AddFolder is nested in a large For loop.

dim i,itemsAdded, size,decimal as integer
dim f as folderitem
dim sizeStr, Kind as string
dim Today as date
Today=new date
f=getfolderItem(cell(Row,PathColumn))
for i=1 to f.Count
If f.item(i).visible then
If f.item(i).directory = true then //Checks if the file is a folder
me.AddFolder f.item(i).name //This adds a new folder to the list
me.RowPicture(me.lastindex) = app.ResourceFork.getcicn(222)
Kind = "Folder"
ElseIf f.item(i).mactype = "APPL" then //Checks if the file is an application
me.Addrow f.item(i).name //Lines like this add a row to the listbox, which stand for a file in the folder being viewed
me.RowPicture(me.lastindex) = app.ResourceFork.getcicn(333) //Lines like this add a picture to the row being created. The row is grabbed from a cicn resource in the app.
Kind = "Application"
ElseIf f.item(i).mactype = "SITD" then //Checks if the file is a Stuffit archive
me.Addrow f.item(i).name
me.RowPicture(me.lastindex) = app.ResourceFork.getcicn(444)
Kind = "Document"
ElseIf f.item(i).mactype = "TEXT" then //Checks if the file is a text file
me.Addrow f.item(i).name
me.RowPicture(me.lastindex) = app.ResourceFork.getcicn(555)
Kind = "Document"
ElseIf f.item(i).mactype = "clpt" then //Checks if the file is a text clipping
me.Addrow f.item(i).name
me.RowPicture(me.lastindex) = app.ResourceFork.getcicn(666)
Kind = "Text Clipping"
Else //If the file non of the above it is given a generic document icon
me.Addrow f.item(i).name
me.RowPicture(me.lastindex) = app.ResourceFork.getcicn(111)
Kind = "Document"
End If
itemsAdded=itemsAdded+1
//put the path in a non-visible column
cell(row+itemsAdded,PathColumn)=f.item(i).absolutepath
//put in the mod date
if f.item(i).modificationDate.DayofYear=(Today.DayofYear-1) then
cell(row+itemsAdded,1)="Yesterday"
else
if f.item(i).modificationDate.shortDate=Today.shortDate then
cell(row+itemsAdded,1)="Today"
else
cell(row+itemsAdded,1)=f.item(i).modificationDate.AbbreviatedDate
end if
end if
//handle the size column
if f.item(i).directory then
sizeStr="-"
else
size=f.item(i).length
if size<1000 then
sizeStr=Str(size)+" bytes"
else
if size<1000000 then
sizeStr=Trunc(size/1000,0)+"K"
else
sizeStr=Trunc(size/1000000,2)+"MB"
end if
end if
end if
cell(row+itemsAdded,2)=sizeStr
//now handle the kind column
cell(row+itemsAdded,3)=Kind
end if //it's visible
Next
exception outofboundsexception
msgBox "Error: "+str(i)
Personal tools