Here's a sample that should show you how to do it. Just cut and paste into
a .PRG and run it. Note the Form DataCheck method and the
Grid.BeforeRowColChange code. Uses data buffering, GETFLDSTATE and OLDVAL.
I tried to remove as much "clutter" as I could, so I hope you can at least
follow it.
PUBLIC frm
frm = CREATEOBJECT("form1")
frm.show()
**************************************************
*-- Form: form1 (g:\code\worktodo\gridrow.scx)
*-- ParentClass: form
*-- BaseClass: form
*-- Time Stamp: 11/21/13 12:42:12 PM
*
DEFINE CLASS form1 AS form
DoCreate = .T.
Caption = "Form1"
Name = "Form1"
ADD OBJECT grid1 AS grid WITH ;
Height = 200, ;
Left = 30, ;
Top = 10, ;
Width = 320, ;
Name = "Grid1"
PROCEDURE datacheck
LOCAL m.cFldState, m.cChanges, m.xx, aFlds[1,1], m.cFld, aChanges[1],
m.nChgs
m.cFldState = GETFLDSTATE(-1,"GridData")
IF ISNULL(m.cFldState)
RETURN
ENDIF
m.nChgs = 0
m.cChanges = ""
AFIELDS(aFlds,"GridData")
FOR m.xx=2 TO LEN(m.cFldState) && skip delete status
m.cFld = aFlds[m.xx-1,1]
IF SUBSTR(m.cFldState,m.xx,1)="2" AND
OLDVAL(m.cFld,"GridData")<>GridData.&cFld
m.cChanges = m.cChanges + m.cFld+[:
"]+ALLTRIM(TRANSFORM(OLDVAL(m.cFld,"GridData")))+;
[" to "]+;
ALLTRIM(TRANSFORM(GridData.&cFld))+["]+ CHR(13)
m.nChgs = m.nChgs + 1
DIMENSION aChanges[m.nChgs]
aChanges[m.nChgs] = m.cFld
ENDIF
IF SUBSTR(m.cFldState,m.xx,1)="4"
m.cChanges = m.cChanges + m.cFld+[: "]+;
ALLTRIM(TRANSFORM(GridData.&cFld))+["]+ CHR(13)
m.nChgs = m.nChgs + 1
DIMENSION aChanges[m.nChgs]
aChanges[m.nChgs] = m.cFld
ENDIF
ENDFOR
IF NOT EMPTY(m.cChanges) AND MESSAGEBOX("Keep
Changes?"+CHR(13)+CHR(13)+m.cChanges,;
4+32+256,;
"Data changed")<>6
TABLEREVERT(.f.,"GridData")
ELSE
TABLEUPDATE(1,.T.,"GridData")
ENDIF
RETURN
ENDPROC
PROCEDURE Load
CREATE CURSOR griddata (f1 c(10), f2 i, f3 d)
INSERT INTO griddata VALUES ("first",1,DATE())
INSERT INTO griddata VALUES ("second",2,DATE()+1)
INSERT INTO griddata VALUES ("third",3,DATE()+2)
GO TOP
SET MULTILOCKS ON
CURSORSETPROP("Buffering",5,"griddata")
ENDPROC
PROCEDURE grid1.BeforeRowColChange
LPARAMETERS nColIndex
IF BITAND(this.RowColChange,1)>0 && Row change 1 or 3
this.Columns(nColIndex).Text1.SetFocus() && Forces data update!
thisform.DataCheck()
ENDIF
ENDPROC
ENDDEFINE
*
*-- EndDefine: form1
**************************************************
Fred
On Thu, Nov 21, 2013 at 11:18 AM, Gene Wirchenko <[email protected]> wrote:
> At 03:51 2013-11-21, Peter Cushing <[email protected]> wrote:
>
>> Gene Wirchenko wrote:
>>
>>> Dear Vixens and Reynards:
>>>
>>> I have been working on something else, and now, I come back to
>>> grids.
>>>
>>> I have asked this question before, but not gotten an answer that
>>> works. I am asking again just in case someone does know how to do this or
>>> even has a good lead. I really do not want to have try to code a
>>> workaround for this, because it is liable to be very nasty with *lots* of
>>> events to handle.
>>>
>>> I am also very puzzled that grids seem to be used a lot by others,
>>> and I have not read about this issue.
>>>
>> I have come to the conclusion that it is much easier to allow them to
>> enter anything then don't allow them a save until they have fixed all the
>> errors. You can have a form level validate function that can check each
>> field in turn and if you have an error description in your cursor you can
>> upate this. Even
>>
>
> It is easy to do that. That is *NOT* what I am asking about. You
> are not the only one missing this. There is a reason that I keep writing
> "row-level".
>
> I am referring to validations that have to be done at the row-level.
> An individual control value might be a valid value, and another one in the
> row might be a valid value, but the two together might be an invalid
> combination. I wish to catch those errors. That is where I have the
> difficulty, because I can not reliably get the control values.
>
>
> if they have multiple errors you just show the first one, then they fix
>> that and it will show the next etc etc. When all error fixed they can save
>> it. You can show the error description by using a label and code in
>> mygrid.afterrowcolchange.
>>
>
> Which would mean that the row change would occur. If there is an
> error, I do not want the row change to occur.
>
>
> The user should know what needs to be entered anyway, so there should not
>> be that many errors. If they don't they need training.
>>
>
> Errors in this app can be expensive. We would rather that they not
> be made.
>
>
> I have just done a form with validation on up to 10 fields per row and
>> can explain a bit more if you are interested.
>>
>
> I have created forms with row-level validation for years. I know how
> to do that. It is the hooks to get the row-level validation to work with
> grids that is the issue.
>
> What we need is a browse with full validation. I thought that grid
> could do this. Either it can not, or there is a lot of work ahead for me.
>
> Sincerely,
>
> Gene Wirchenko
>
>
>
[excessive quoting removed by server]
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message:
http://leafe.com/archives/byMID/profox/CAJCBkso8QpRTGCrC8E7ouzWBVG_yH+q5RV-=-g16racy71s...@mail.gmail.com
** All postings, unless explicitly stated otherwise, are the opinions of the
author, and do not constitute legal or medical advice. This statement is added
to the messages for those lawyers who are too stupid to see the obvious.