addItemsFromArray example
The following example shows how to use the form's onOpen event using it's listView object with addItemsFromArray method to programatically add Items involving dBASE files (dbf, wfm, prg and rep) to a ListView object.
function form_onOpen()
//populate the listview with dBASE Files each type in it's own group
//Get list of files
aDir = new array()
aDir.dir()
aFiles = new array()
for x = 1 to aDir.size/5
if NOT ("D" $ aDir[x,5] OR "S" $ aDir[x,5] OR "H" $ aDir[x,5])
//it is a file with no attributes like system Hidden or directory
aFiles.add(aDir[x,1]) //add file name
endif
endfor
//remove backups
if aFiles.size>0
for x = aFiles.size to 1 step -1
//take out backups
if "backup" $ lower(aFiles[x])
aFiles.delete(x)
aFiles.size = aFiles.size-1 //decrement size of array
endif
endfor
endif
?afiles.size
if aFiles.size>0 //if there are still files in the array after removing backups
//get list of only the files types I want to see
adBASEFiles = new array()
for x = 1 to afiles.size
if ".dbf" $ lower(aFiles[x]) OR ;
".prg" $ lower(aFiles[x]) OR ;
".wfm" $ lower(aFiles[x]) OR ;
".rep" $ lower(aFiles[x])
adBASEFiles.add(aFiles[x])
endif
endfor
endif
form.listview1.additemsfromArray(adBASEFiles)
form.listview1.mode = 2 //List
?"total items "+form.listview1.itemcount
return