Wiki Home

Sample Grid Prg


Namespace: VFP
Here is prg that makes a form, grid and a few buttons.
It is a good start for making simple grid problem examples.

SET DELETED on

CREATE CURSOR foo (cFid1 char(10))
INSERT INTO foo VALUES ("A")
INSERT INTO foo VALUES ("B")
INSERT INTO foo VALUES ("C")
LOCATE 

lof = CREATEOBJECT("TestForm")
lof.visible = .t.

READ EVENTS

DEFINE CLASS TestForm as Form

	PROCEDURE init()

      WITH THIS 
      
        .ADDOBJECT('cmdCancel', 'cCancel' )
            .cmdCancel.VISIBLE = .T.
        .ADDOBJECT('cmdDelete', 'cDelete' )
           .cmdDelete.VISIBLE = .T.

		.AddObject("grid1","grid")
			.grid1.visible = .t.
	  
	  ENDWITH 

	ENDPROC
	
ENDDEFINE 

DEFINE CLASS cCancel AS COMMANDBUTTON
    CANCEL = .T.
    CAPTION = "Close"
    HEIGHT = 25

  PROCEDURE init()
    this.TOP = thisform.HEIGHT - this.HEIGHT - 5
    this.LEFT = thisform.WIDTH - this.WIDTH - 5
    this.ANCHOR = 12
  ENDPROC 
   	
  PROCEDURE CLICK 
        THISFORM.RELEASE()
        CLEAR EVENTS 
  ENDPROC
ENDDEFINE

DEFINE CLASS cDelete AS COMMANDBUTTON
    CAPTION = "Delete"
    HEIGHT = 25

  PROCEDURE init()
    this.TOP = thisform.HEIGHT - this.HEIGHT - 5
    this.LEFT = thisform.WIDTH - this.WIDTH - 150
    this.ANCHOR = 12
  ENDPROC 

  PROCEDURE CLICK 
	IF BETWEEN( RECNO(), 1, RECCOUNT() )
		DELETE
		SKIP
		thisform.Grid1.refresh()
	ELSE
		MESSAGEBOX("Nothing to Delete")
	ENDIF 
  ENDPROC

ENDDEFINE


Carl Karsten
( Topic last updated: 2006.11.10 12:11:48 PM )