Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Validating edits in a grid
Message
From
02/11/2007 13:19:14
 
 
To
01/11/2007 15:40:57
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Environment versions
Visual FoxPro:
VFP 8 SP1
OS:
Windows 2000 SP4
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01265853
Message ID:
01266147
Views:
19
>Hi All,
>
> I have a grid on a form, where the user clicks on a 're-name' button, and the code sets focus to the grid in the row that they were on when they clicked the button. If they try to move to another row, either by arrows or by clicking in the new row with the mouse, I have code in the valid and afterrowcolumnchange to put the grid back to readonly, so they can not edit a row that they were not on, when they pressed the 're-name' button. There are some records that they are not allowed to re-name, and the 're-name' button is grayed out when they are on these records. I need to check the title that they have typed in, but I can not seem to get the code into the correct method. The code is a function that sends back true or false. I have it in the grid.valid, grid.aftercolumnchange, grid.keypress (for when they hit {enter}), in the textbox with in the grid, I have it in textbox.keypress (for when they hit {enter}), textbox.lostfocus, and textbox.valid.
>
>We want the grid to act like windows explorer. When you hit the 're-name' button, it opens the file name already selected into edit mode. if you move off of that file, edit mode is closed. And the new name is checked against what is already out there, if matchs, error is detected, messagebox comes up and you do not get out of that edit window.
>
>Any Ideas?
>
>Thanks in Advance,
>Beth


Hi Beth,
Using your description I created a form with a command button and a grid.

I placed some code in the Load to create a data source for my grid. Here the code for the load:
CREATE CURSOR ztest (cFileName C(20),cDescription C(30),nNumber N(3))
INSERT INTO zTest (cFileName,cDescription,nNumber) VALUES ("Doc1.doc","Inventory doc",1)
INSERT INTO zTest (cFileName,cDescription,nNumber) VALUES ("Doc2.doc","Customer doc",2)
INSERT INTO zTest (cFileName,cDescription,nNumber) VALUES ("Doc3.doc","Supplier doc",3)
GO top
In the init of the form I placed the following:
*--set all columns to readonly
This.grid1.SetAll("ReadOnly",.t.,"Column")  
I also create a form property name pcFileName to save a current value of the field the user is going to modify (in my case it is cFileName). I will use it later in the valid even of the Text box of the first column of the grid.


The "click" event of the command button will have the following code:
*--make first column of the grid editable
thisform.grid1.column1.ReadOnly =.f.
thisform.grid1.column1.text1.SetFocus()
The rest of the code belong to the grid1.column1.text1
grid1.column1.text1.GotFocus:
*--save the current value
Thisform.pcoldfilename=This.Value
grid1.column1.text1.Valid:
LOCAL lnRecno,lcText,lReturn
lReturn=.t.
*--save current record
lnRecno=RECNO("Ztest")
lctext=This.Value
*--check for duplicates
SELECT zTest.cFileName FROM zTest ;
WHERE cFileName=lcText AND RECNO()<>lnRecno INTO CURSOR zdupl

IF _tally<>0
	=MESSAGEBOX("Name already in use")
	*--restore the old value
        replace ztest.cFileName WITH thisform.pcoldfilename IN zTest
	lReturn=.f.
ENDIF
SELECT zTest
*-- if duplicate keep this object focused
return IIF(lReturn,.t.,0)
grid1.column1.text1.LostFocus:
*-- reset to be readonly
This.Parent.ReadOnly =.t.
grid1.column1.text1.KeyPress:
LPARAMETERS nKeyCode, nShiftAltCtrl
IF nKeyCode=27
	*--escape key - loose the focus
	Thisform.command1.SetFocus()
ENDIF
I hope this helps.
Yelena
Previous
Reply
Map
View

Click here to load this message in the networking platform