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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

BeforeRowColChange AfterRowColChange. Displaying the deleted record 1

Status
Not open for further replies.

sashaDG

Programmer
Jun 20, 2022
112
0
16
BY
Hi all.
case1. There is a pageform.p1 main_grid, when i'm double-clicking on the line X, pageform.page2 opens with the "delete" button.

When I click delete: I move to the grid, X is not in the grid.(It's good)

case2. But when I start the application first, then I add rows from another table. And when I want to delete X, I click on the button and move to the main_grid, but the deleted record X is displayed (marked with a black mark) and the focus is set on it. To make line X disappear, I need to click on any other line. How to make it be like in the first case?

Click in main_grid
ThisForm.Pageframe1.page1.Refresh
ThisForm.Pageframe1.page2.Refresh

When i removed ThisForm.Pageframe1.page1.Refresh, then
me said:
To make line X disappear, I need to click on any other line.
stopped working, then the problem is in the page refresh?


I noticed that in the first case debugger has BeforeRowColChange AfterRowColChange
1_njscpi.png


case2:
2_eagd34.png


delete button
SELECT main_dir
DELETE

ThisForm.Pageframe1.ActivePage = 1
ThisForm.Pageframe1.page1.Enabled = .T.
ThisForm.pageframe1.page1.grdMain_dir.SetFocus

ThisForm.pageframe1.page1.grdMain_dir.Refresh
*!* ThisForm.pageframe1.page1.Refresh​

Note: if I write GO BOTTOM after DELETE, then the deleted record will disappear, but I need the focus to remain in the previous place
 
SKIP 1 or SKIP -1 would be a solution. Well, or both.

Also Control.Setfocus() works better than control.Refresh() most of the time. It's true for the grid, combobox, and listbox, at least.

Chriss
 
Hi,

I assume that you know that deleting a record in VFP is a two step process: 1) you mark it for deletion and 2) then you make it "vanish". You have several options to do sub 2) (see Chriss's post and have a look at the code below). Even if they are not visible they still exist and may be RECALLED. Only after the table is PACKED are they "gone".

Code:
PUBLIC goForm1

goForm1=NEWOBJECT("form1")
goForm1.Show

Read Events

Close all
Clear All

RETURN


**************************************************

DEFINE CLASS form1 AS form
	AutoCenter = .T.
	Caption = "Grid with calculated columns"
	MinHeight = This.Height
	MinWidth = This.Width
	MaxWidth = This.Width
	Themes = .F. 
	
	ADD OBJECT cmdDelete as CommandButton WITH ;
		Left = 12, ;
		Top = 12, ;
		Height = 24, ;
		Caption = "Delete"
		
		PROCEDURE cmdDelete.Click()
			SET DELETED ON && make sure set deleted is on
			DELETE NEXT 1
			WAIT WINDOW + "Now the record is marked for deletion" ;
						+ CHR(13) + "Then the form will be refreshed in order to have the deleted record vanish" TIMEOUT 5
						
			ThisForm.Refresh()
		
		ENDPROC  
 
	ADD OBJECT cmdShow as CommandButton WITH ;
		Left = 120, ;
		Top = 12, ;
		Height = 24, ;
		Caption = "Show Deleted"
		
		PROCEDURE cmdShow.Click()
			SET DELETED OFF 
			SET FILTER TO DELETED()
			LOCATE

			ThisForm.Refresh()
			
			WAIT WINDOW + "The deleted records are shown for 10 seconds and will disappear again" TIMEOUT 10
			
			SET DELETED ON 
			SET FILTER TO 
			LOCATE
									
			ThisForm.Refresh()
		
		ENDPROC  

	ADD OBJECT grid1 AS grid WITH ;
		ColumnCount = 4, ;
		Left = 12, ;
		Top = 42, ;
		Width = ThisForm.Width - 24, ;
		Height = ThisForm.Height - 54, ;
		BackColor = RGB(210, 210, 210), ;
		Anchor = 15
		
		PROCEDURE grid1.Init
		
			UPDATE csrData SET f3 = f1*f2, f4 = f1/f2
			
			LOCATE 

			This.RecordSource = "csrData"
			
			 WITH This.Column1
			  .Header1.Caption = "F1"
			  .ControlSource = "F1"
			  .AddObject("txtF1", "txtTextBox")
			  .CurrentControl = "txtF1"
			  .txtF1.Visible = .T.
			  .Sparse = .F.
			 ENDWITH

			 WITH This.Column2
			  .Header1.Caption = "F2"
			  .ControlSource = "F2"
			  .BackColor = RGB(210, 210, 210)
			  .ReadOnly = .T.
			 ENDWITH

			 WITH This.Column3
			  .Header1.Caption = "F1 * F2"
			  .ControlSource = "F3"
			  .BackColor = RGB(210, 210, 210)
			  .Sparse = .F.
			  .ReadOnly = .T.
			  .Text1.InputMask = "9,999,999.99"
			 ENDWITH

			 WITH This.Column4
			  .Header1.Caption = "F1 / F2"
			  .ControlSource = "F4"
			  .BackColor = RGB(210, 210, 210)
			  .Sparse = .F.
			  .ReadOnly = .T.
			  .Text1.InputMask = "9,999,999.99"
			 ENDWITH
		 ENDPROC 
		 
PROCEDURE Destroy
	CLOSE ALL
	Clear Events

ENDPROC

PROCEDURE Load
	LOCAL i

	CREATE CURSOR csrData (f1 I, f2 I, f3 N(12,2), f4 N(12,2))

	FOR i = 1 TO 500
		INSERT INTO csrData VALUES ( Int(Rand()*1001), Int(Rand()*999) + 1, 0, 0)
	ENDFOR
	
ENDPROC

ENDDEFINE

*********************************************

DEFINE CLASS txtTextBox as TextBox

	BackColor = RGB(0, 210, 210)
	
	PROCEDURE LostFocus() && () InterActiveChange()
*!*		You have different choices to update - all three work

*!*			LOCAL liRecNo
*!*			
*!*			liRecNo = RECNO()
*!*			
*!*			UPDATE csrData SET f3 = f1*f2, f4 = INT(f1/f2) WHERE RECNO() = liRecNo

		Replace f3 WITH f1 * f2, f4 WITH f1/f2 && also works
		
*!*			Replace f4 with This.Value * f3 && also works
			
	ENDPROC 
ENDDEFINE 


*********************************************

hth

MarK
 
To remove deleted records from displayed, use the SET DELETED ON command. This removes records that are marked for deletion. SET DELETED OFF allows deleted records to be displayed. Do a grid refresh to see the effect.

Greg
 
Watch out for eof()

Code:
IF !EOF()
  SKIP
ENDIF

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.

There is no place like G28 X0 Y0 Z0
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top