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 topIn 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.
*--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
*--save the current value Thisform.pcoldfilename=This.Valuegrid1.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() ENDIFI hope this helps.