Microsoft KB Archive/140295

= How to Replace a Grid Cell's Value with Previous Cell's Value =

Article ID: 140295

Article Last Modified on 2/10/2000

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition

-



This article was previously published under Q140295



SUMMARY
You can replace the value in a grid cell with the value contained in the grid cell that lies above it. This article shows by example how to create a command button on a form that can perform this operation.



Step-by-Step Example
 Create a new form, and add a table to the data environment. Drag the table from the data environment onto the form to create a new grid.  Place a command button on the form, and add the following code to its click event: ThisForm.Grid1.SetFocus ThisForm.LockScreen = .T.  IF ThisForm.Grid1.RelativeRow = 1 =MESSAGEBOX("You cannot do this replacement from the top "+;        "of the Grid.",16,"") *: If the active grid cell is in the top row of the grid, this *: will display a message to the user. ELSE RepField = FIELD(ThisForm.Grid1.ActiveColumn) ColumnNumber = "Column"+ALLTRIM(STR(ThisForm.Grid1.ActiveColumn)) ThisForm.GRID1.ACTIVATECELL(ThisForm.GRID1.RELATIVEROW-1,;        ThisForm.GRID1.RELATIVECOLUMN) RepValue = ThisForm.Grid1.&ColumnNumber..Text1.Value ThisForm.GRID1.ACTIVATECELL(ThisForm.GRID1.RELATIVEROW+1,;        ThisForm.GRID1.RELATIVECOLUMN) yesno = MESSAGEBOX("Are you certain that you wish to replace "+;        CHR(13)+"Field "+UPPER(repField)+" current value?",36,"") IF yesno = 6 REPLACE &RepField WITH RepValue ThisForm.REFRESH ELSE WAIT WINDOW "Replacement Canceled" NOWAIT ENDIF ENDIF ThisForm.LockScreen = .F.                        Close, Save, and use the DO command to run the form. Place the insertion point in any cell of the grid, and click the command button. If the pointer has been placed in a cell that is in the top row of the grid, you should observe the "You cannot do this replacement from the top of the grid" message. Otherwise, you should see the "Are you certain..." message. If you click Yes, the replacement should occur. If you click No, a wait window indicating "Replacement Canceled" should appear.

Additional query words: VFoxWin

Keywords: kbcode KB140295

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.