Welcome to MSDN Blogs Sign in | Join | Help

How to display a list of files in a grid

I received a question from a customer:

 

I am trying to find a way to display a grid of files (specifically DBF files) and show them in the order they were created with the dates and file sizes. 

 

I just took the sample code from Add a slider control to your TreeMap to vary how much detail is shown and cut/paste and the result is below.

It uses the  AllowCellSelection property which allows the grid to mimic a listbox.

 

 

 

CLEAR ALL

CLEAR

PUBLIC oForm

oForm=CREATEOBJECT("MyForm",ADDBS(GETDIR("c:\program files")),"*.exe",.f.)

 

DEFINE CLASS MyForm as Form

          AllowOutput=.f.                 && so '?' output goes to screen

          Width=_screen.Width

          Height=_screen.Height-50

          Width=1024

          Height=798

          PROCEDURE init(cPath as String, cMask as string, fSubDir as Boolean)

                   SET EXCLUSIVE OFF

                   SET SAFETY OFF

                   SET TALK off

                   SET EXACT OFF

                   CREATE table Files (path c(240),fname c(240),fsize n(10,0),timestamp t)

                   this.DoDir(cPath,cMask)

                   INDEX on timestamp DESCENDING TAG t   && choose your desired order

*                  INDEX on fsize DESCENDING TAG fsize

                  

                   this.AddObject("gr","grid")

                   this.gr.AllowCellSelection=.f.

                   this.gr.Visible=1

                   this.gr.Height=thisform.Height

                   this.gr.Width = thisform.Width

                   this.gr.Autofit

                   this.gr.Column3.InputMask="999,999,999"

                   this.Show

          PROCEDURE DoDir(cPath as String, cMask as String)

                   LOCAL n,i,aa[1]

                   n=ADIR(aa,cPath+cMask,"",1)

                   FOR i = 1 TO n

                             INSERT INTO files (Path,fname,fsize,timestamp) VALUES ;

                                      (cPath, aa[i,1], aa[i,2],CTOT(DTOC(aa[i,3])+aa[i,4]))

                   ENDFOR

                   n=ADIR(aa,cPath+"*.*","HD",1)     && now without the mask, search for directories

                   FOR i = 1 TO n

                             IF "D"$aa[i,5] && if it's a dir

                                      IF aa[i,1] != '.'

                                                this.DoDir(cPath+aa[i,1]+"\",cMask)         && recur

                                      ENDIF

                             ENDIF

                   ENDFOR

ENDDEFINE

 

Published Monday, July 31, 2006 11:11 PM by Calvin_Hsia
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: How to display a list of files in a grid

Monday, August 14, 2006 12:55 PM by Calvin_Hsia
The timestamp code is slightly wrong: need to add a space between the date and time before calling DTOC():

aa[i,3])+" "+aa[i,4]

# Smith

Thursday, April 05, 2007 11:04 AM by Smith

Hey, I have some links here,thanks.

# foxpro.catalyst ?? » Blog Archive » CHsia: How To Display A List of Files in A Grid

# Good site

Friday, January 16, 2009 12:01 PM by garry-yw

<a href= http://ikdoeei.angelfire.com >cowpiebunkhouse</a> <a href= http://kosaaea.angelfire.com >beverly kirk and wjla</a> <a href= http://lowiozi.angelfire.com >aaa and radio and format</a> <a href= http://eheqibs.angelfire.com >waterford logo year started</a> <a href= http://nwcijgg.angelfire.com >i fi had a dream tonight id dream that id be with you lyrics</a>

# Good site

Monday, April 06, 2009 7:35 PM by jyner_jo

<a href= http://index1.frigats.ru >������ ����� ���������</a> <a href= http://index2.frigats.ru >������� mp3 ���������</a> <a href= http://index3.frigats.ru >����� ���� �� ��������</a> <a href= http://index4.frigats.ru >����� �������� ��� ������</a> <a href= http://index5.frigats.ru >������� �������� ����� ����</a>

# Calvin Hsia s WebLog How to display a list of files in a grid | alternative dating

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker