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!

When uisng GRID, Deal with BUILDER or Manually define column ?

Status
Not open for further replies.

stvhui

Programmer
Jul 17, 2002
13
0
0
ID
Hello to you,
I'm uisng vfp7

When Using GRID, Do you deal with GRID BUILDER or create it manually ?

What's the advantage and dis-advantage between it ?

I doubt to choose it because :
1. my data is freetable & ms-sql server (by sqlpassthru)
if I using freetable, I can flashly to contruct the grid by builder. but when using sqlpasstrhu, I cann't because I don't the physical table.
2. If I using builder, it is easy to programmed the header's click or text1.click (that's frequent asked in this forum) but I using manually to create grid, I've no idea to implement it.

I meant I wanna have form files (scx) that contains some controls like grid,textbox,combobox etc
How to construct the grid by code that have ability of textbox's click event

Please advice & give me the example code
Steven
 
Here some code to show you how to add a click event to both the header and the textbox events. The trick is to add your own controls to the grid, instead of using the existing ones.:
Code:
CREATE CURSOR myCursor (NAME c(20),lname c(20),fname c(20))
GO BOTT
APPEND BLANK
oForm = CREATEOBJECT("form")
oForm.ADDOBJECT("Grid2","GRID1")
FOR EACH oColumn IN oForm.grid2.COLUMNS
	oColumn.ADDOBJECT("myheader1","_myheader")
	oColumn.ADDOBJECT("text3","text2")
	oColumn.CURRENTCONTROL ="text3"
ENDFOR
oForm.SHOW(1)
DEFINE CLASS grid1 AS GRID
	COLUMNCOUNT = 3
	VISIBLE = .T.
	RECORDSOURCE = "mycursor"
ENDDEFINE
DEFINE CLASS text2 AS TEXTBOX
	VISIBLE = .T.
	PROCEDURE CLICK
	MESSAGEBOX(TRANSFORM(this.parent.name)+" click was used")
ENDPROC
ENDDEFINE

DEFINE CLASS _myheader AS HEADER
	PROCEDURE CLICK
	WAIT WINDOW TRANSFORM(THIS.PARENT.NAME)+" was clicked" NOWAIT
ENDPROC
ENDDEFINE
 
HI
The choice is yours... You can use a builder or do it manualy. Regarding your question..
"How to construct the grid by code that have ability of textbox's click event"... I have posted a sample form with a grid.. Copy the following and save it as a prg.. Run it and explore..

************************************************************
** AREAS.prg *** EXAMPLE SOFTWARE
************************************************************
** DUmmy table for example created
CREATE TABLE tArea (AreaCode C(4), AreaName C(30))
USE tArea IN 1 ALIAS areas
INDEX ON areacode TAG areacode
USE

USE tArea ORDER 1 IN 1 ALIAS areas
SELECT areas
SCATTER MEMVAR BLANK
FOR I=11 TO 25
m.AreaCode="A0"+ALLTRIM(STR(i))
m.AreaName = "Area Name "+m.AreaCode
INSERT INTO areas FROM MEMVAR
ENDFOR
LOCATE

** The form created with grid here below....
PUBLIC oform1
oform1=NEWOBJECT("form1")
oform1.Show()
READ EVENTS
RELEASE oForm1
RETURN
************************************************************
** class code for the columns text boxes
** with individual event codes
** You can build an EditBox or a ComboBox
** or a checkBox as you wish ... in the same way
************************************************************
DEFINE CLASS oAreaCode AS textbox

PROCEDURE valid
IF EMPTY(This.Value)
RETURN .f.
ELSE
RETURN .T.
ENDIF
ENDPROC

PROCEDURE click
WAIT WINDOW "Area Code field clciked"
ENDPROC

ENDDEFINE
************************************************************
DEFINE CLASS oAreaName AS textbox

PROCEDURE valid
IF EMPTY(This.Value)
RETURN .f.
ELSE
RETURN .T.
ENDIF
ENDPROC

PROCEDURE click
WAIT WINDOW "Area Name field clciked"
ENDPROC

ENDDEFINE
************************************************************
** The form is created with the grid added in it.
************************************************************
DEFINE CLASS form1 AS form

Caption = "My Grid Form created by PRG"
DoCreate = .T.
Name = "Form1"

ADD OBJECT grid1 AS grid
********************************************************
PROCEDURE Init
DODEFAULT()
ENDPROC

PROCEDURE Destroy
CLEAR EVENTS
DODEFAULT()
ENDPROC
*********************************************************
PROCEDURE grid1.Init
WITH This
.AllowAddNew = .t.
.Visible = .f.
.ColumnCount = 2

.Column1.Width = 60
.Column1.ADDOBJECT("Text2","oAreaCode")
.Column1.CurrentControl = "Text2"
.Column1.REMOVEOBJECT("Text1")

.Column2.Width = 192
.Column2.ADDOBJECT("Text2","oAreaName")
.Column2.CurrentControl = "Text2"
.Column2.REMOVEOBJECT("Text1")

.Visible = .t.
ENDWITH
DODEFAULT()
ENDPROC

ENDDEFINE
************************************************************
** EOF
************************************************************
Hope this helps you :) ramani :)
(Subramanian.G),FoxAcc, ramani_g@yahoo.com
 
Hint: a remore view is faster than SQL pass through.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top