Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need to clear data displayed on a grid 1

Status
Not open for further replies.

titoneon

MIS
Dec 11, 2009
335
US
Hi Everyone, in advance thanks a lot,
I have this code below, well as you know it creates a form,a grid and textoxes, i just want after i pressed the Escape key to stop the processing search in a case that i want to interrupt the searching or stop it, this i can do itno problem is part of the Filer, then after that i want to clear the textboxes values as well the grid data displayed, i already created a command to clear the textboxes and the grid vales but the grid does not clear the displayed data(most likely cause i am not doing it right), please find the line that says "this proced allow me to clear the values on txtboxes and the Grid" there is the proced for that cmdbutton also if you can tell me why the Scrollbar horizontal does not work ?, it is always dimmed, and believe me when data is displayed in the grid, i need to scroll horizontally but it is still dimmed and can not do it.

here is the code in my prg file, you can copy it and run it if you need to test it.


_screen.caption=" Find a File... "
SET SAFETY OFF
Local oForm As Form
oForm = Createobject('Form1')
oForm.Show(1)
Return

Define Class Form1 As Form
Height = 470
AutoCenter = .T.
Caption = "Search Tool..., To Stop Or cancel Press Escape Key "
Width = 655


Add Object label1 As Label With ;
top = 30, Left = 10, Caption = 'Search File', AutoSize = .T.

Add Object txtFile As TextBox With ;
top = 28, Left = 100, Value = '', Width = 200

Add Object label4 As Label With ;
top = 30, Left = 302, Caption = 'Type the Filename and the Extension as(ie.. 12356.dwg', AutoSize = .T.


Add Object label2 As Label With;
Top = 60, Left = 10, Caption = 'Target Folder', AutoSize = .T.

Add Object label3 As Label With;
Top = 85, Left = 140, Caption = 'Input Target Folder Mapped drive Letters as(ie.. O:\;P:\Q:\)' ,AutoSize = .T.

Add Object txtFolder As TextBox With ;
top = 58, Left = 100, Value = '', Width = 400

Add Object cmdFolder As CommandButton With;
top = 56, Left = 505, Caption = '...', Width = 20, Height = 24

Add Object cmdSearch As CommandButton With;
top = 85, Left = 10, Caption = 'Start \<Searching', Width = 120, Height = 24


Add Object chkSub As Checkbox With;
top = 85, Left = 464, Caption = 'Include Sub Folders', Value = 1, AutoSize = .T.

Add Object grid1 As Grid With ;
Top = 120, Left = 10, Height = 300, Width = 600, ColumnCount = 1,;
ForeColor = RGB(0,255,0), deletemark = .F., AllowCellSelection = .F., GridLines = 0, ;
HeaderHeight = 0, RecordMark = .F., ScrollBars = 3

**Width = 600 WAS 550
*
*Add Object grid1 As Grid With ;
Top = 120, Left = 10, Height = 300, Width = 550, ColumnCount = 1,;
deletemark = .F., AllowCellSelection = .F., GridLines = 0, ;
HeaderHeight = 0, RecordMark = .F., ScrollBars = 3


Add Object cmdOpen As CommandButton With;
top = 425, Left = 10, Caption = 'O\<pen File', Width = 120, Height = 24

Add Object cmdExplore As CommandButton With;
top = 425, Left = 150, Caption = 'E\<xplore', Width = 120, Height = 24

Add Object cmdQuit As CommandButton With;
top = 425, Left = 300, Caption = 'Q\<uit', Width = 120, Height = 24

Add Object cmdClearS As CommandButton With;
top = 425, Left = 450, Caption = 'C\<learScreen', Width = 120, Height = 24



Procedure Load
Create Cursor junk (filename Varchar(250))
Declare Integer ShellExecute In shell32.Dll ;
INTEGER hndWin, String cAction, String cFileName, ;
STRING cParams, String cDir, Integer nShowWin
Endproc


** THIS PROCEDURE ALLOW ONLY ONE DRIVE TO BE SEARCHED
*Procedure cmdFolder.Click
* Thisform.txtFolder.Value = Getdir()
*Endproc


** **THIS PROCEDURE BELOW ALLOW MULTIPLEe DRIVES TO BE SEARCHED
Procedure cmdFolder.Click
LOCAL lcFolder, lcFolders
lcFolder = GETDIR()
lcFolders = ALLTRIM(thisform.txtFolder.Value)
lcFolders = IIF(EMPTY(m.lcFolders),'',m.lcFolders+';')+m.lcFolder
* Remove extra ; just in case it was keyed-in as well
Thisform.txtFolder.Value = STRTRAN(m.lcFolders,';;',';')
ENDPROC



Procedure grid1.Init
This.RecordSourceType = 1
This.RecordSource = 'junk'
This.Column1.Width = 530
Endproc

Procedure cmdOpen.Click
ShellExecute(0,"open",Alltrim(junk.filename),"","",1)
Endproc

Procedure cmdExplore.Click
ShellExecute(0,"open",'explorer.exe',Justpath(Alltrim(junk.filename)),"",1)
ENDPROC

Procedure cmdQuit.Click
USE
WAIT clear
Thisform.Refresh
thisform.Release
ENDPROC

** this proced allow me to clear the values on txtboxes and the Grid
PROCEDURE cmdClearS.Click
WAIT clear
thisform.txtFile.Value = ''
THISFORM.txtFolder.Value = ''
THISFORM.GRID1.SETFOCUS
thisform.grid1.Value = 0
thisform.grid1.refresh
Thisform.Refresh
ENDPROC


Procedure cmdSearch.Click
Local lcFile, lcFolder
lcFile = Alltrim(Thisform.txtFile.Value)
* Validate file
If Empty(m.lcFile)
Messagebox('Please type the file to be searched first!',0+64,'Oppppppssss!')
Thisform.txtFile.SetFocus
Return(.F.)
Endif

lcFolder = Alltrim(Thisform.txtFolder.Value)
* Validate folder
If Empty(m.lcFolder)
Messagebox('Please Select the folder to be searched first!',0+64,'Oppppppssss!')
Thisform.txtFolder.SetFocus
Return(.F.)
Endif

**** Here is the loop, GetWordCount() and GetWordNum()
lnPaths = Getwordcount(m.lcFolder,';')
Zap In junk
For lnCtr = 1 To m.lnPaths
lcPath = Getwordnum(m.lcFolder,m.lnCtr,';')
Wait Window 'Working on '+m.lcPath+'......' NOWAIT &&NOCLEAR
Thisform.SearchMe(m.lcPath, m.lcFile)
Next
Wait Clear
Go Top

** new by ep
if empty(junk.filename)
Messagebox('File does not exist on any drive..',0+64,'Oppppppssss!')
endif
** end new by ep
Thisform.grid1.Refresh
Endproc

Procedure SearchMe
Lparameters lcPath, lcFile
* start Searching
Local loFiler As Filer.fileutil, lnloop, lnCtr, lcPath, lnPaths
loFiler = Createobject('filer.fileutil')
With loFiler
.SearchPath = m.lcPath
.Subfolder = Thisform.chkSub.Value
.FileExpression = m.lcFile
.Find(0)
For lnloop=1 To .Files.Count
lcFile = Addbs(.Files(m.lnloop).Path)+.Files(m.lnloop).Name
Insert Into junk Values (m.lcFile)
Endfor
Endwith
loFiler = .Null.
Endproc
Enddefine
 
Unlike other controls, grids do not have a Value property and cannot display data without being bound to some kind of cursor. To empty a grid, you must empty the cursor "under" the grid. In your case, you're using a cursor named "junk":

Code:
SELECT junk
ZAP

ZAP is a destructive command if used in the wrong workarea, so use it judiciously.
 
In addition to Dan's reply, I always use "ZAP [IN nWorkArea | cTableAlias]" command just to be sure you're Zapping the correct one.

Auguy
Sylvania/Toledo Ohio
 
Actually I usually do it by first creating an Index with a Condition on it.

Something like:
Code:
SELECT MyGridsTable
INDEX ON Cust_ID TAG Cust_ID FOR !DELETED()

Then instead of doing a ZAP on the table/cursor, I merely DELETE all the records that I want to 'disappear'.

Code:
SELECT MyGridsTable
DELETE ALL FOR DontWant = .T.
ThisForm.Grid1.Refresh

Good Luck,
JRB-Bldr
 
Thanks to get back to me, I already figured out the zap but thanks a lot, going back to the scrollbar property=3 question, there is not only the filename exposed in the grid, this include the folders and subfolders as well where the filename is located, what I meant is when the line or row is too long(cause include all the path where is located the filename), the scrollbar horizontal should allow me to move it and see until the end of the row, I mean if I can't see the whole row then I should be able to scroll from left to right shouldn't I ?
is there anyway for this ? unless I need to increase the length of the field, by the way what is the maximum length for Varchar field in vfp 9.0, problably I need to make this longer, that is probably the reason some of the row got cut off.
Thanks
 
The file name length can be 260 chars max in NTFS, you can try that out by generating such a long file name, a varchar field max is 254, like char. So indeed for the few cases you need the full 260 chars you rather need a memo for file names, but varchar(254) should be fine. It's harder to show a memo content, you need to replace the textbox in the grid column with an editbox and set column sparse=.f.

Besides that, the column width is the column width. The scrollbar only appears, if your columns widths are larger than the grid width, but columns don't resize automatically, if values in them don't fit.
If you didn't remove the deletemark AND the recordmark, and didn't remove grid headers, you will have a small sqare/rectangle area at the top left of the grid. Double click that, and columns resize. Also you can resize columns at the header, when moving the mouse at the left or right header border, at the line between headers. Then the mouse arrow turns into a left/right arror indiciating you can now move that border and resize a column by that, when you click and hold the left mouse button. That's working exactly the smae way as resizing columns in Windows Explorer in a list/detail view of a folder.

Bye, Olaf.
 
Titoneon,

You might also consider providing a control that calls the grid's AutoFit method. That will allow the user to resize the columns so that they are only big enough to show the widest actual data, and no wider. That way, your wide filename column will usually shrink down to a more manageable width (on the basis that most filenames are fewer than 260 characters).

Even so, the horizontal scrollbar will only be active if there are more columns to show, outside the current visible width of the grid. You don't get the scrollbar merely to scroll within a column.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top