回复 11楼 wxzd123
加一句visible=.t.,添加自定义控件时,默认visible是.f.的。我写了下面代码测试了一下,vfp9.0+win7下通过
程序代码:
** Test.prg
of = CREATEOBJECT("Form1")
of.show(1)
RETURN
DEFINE CLASS Form1 As Form
ADD OBJECT Command1 AS CommandButton WITH top=10,left=10,height=25,caption="切换表"
PROCEDURE Init
ENDPROC
PROCEDURE Command1.Click
USE
IF VARTYPE(thisform.Grid1) == "O"
thisform.RemoveObject("Grid1")
ENDIF
thisform.AddObject("Grid1", "_Grid")
thisform.Grid1.Top = 40
thisform.Grid1.Left = 10
IF EMPTY(this.Tag)
this.Tag = "1"
* 相当于 use 表1
CREATE CURSOR 表1 (f1 I, f2 I, f3 I,f4 I)
INSERT INTO 表1 VALUES (1, 2, 3,4)
INSERT INTO 表1 VALUES (5, 6,7,8)
GO TOP
thisform.Grid1.RecordSource = "表1"
thisform.grid1.changetextbox()
thisform.Refresh()
ELSE
this.Tag = ""
* 相当于 use 表2
CREATE CURSOR 表2 (f1 I, f2 I, f3 I, f4 I)
INSERT INTO 表2 VALUES (4, 5, 6,7)
INSERT INTO 表2 VALUES (8, 9,10,11)
GO TOP
thisform.Grid1.RecordSource = "表2"
thisform.grid1.changetextbox()
thisform.Refresh()
ENDIF
ENDPROC
ENDDEFINE
DEFINE CLASS _Grid AS Grid
Visible = .T.
* ColumnCount [color=#808080]= 3[/color]
RecordSourceType=1
PROCEDURE changetextbox
FOR i=1to this.columncount
this.Columns(i).RemoveObject("Text1")
this.Columns(i).AddObject("Text1", "_TextBox")
this.Columns(i).visible=.t.
ENDFOR
ENDPROC
ENDDEFINE
DEFINE CLASS _TextBox AS TextBox
Visible = .T.
PROCEDURE KeyPress(nKeyCode, nShiftAltCtrl)
IF nkeycode=13
*MESSAGEBOX(this.value+1)
*下面代码将在表格最后一行敲回车键后进入下一行
IF RECNO()<RECCOUNT() AND thisform.grid1.activecolumn=FCOUNT()
NODEFAULT
SKIP
thisform.grid1.activatecell(RECNO(),1)
ENDIF
ENDIF
ENDPROC
PROCEDURE Click
*MESSAGEBOX(this.value)
*nposition=LEN(STR(this.value))-OCCURS(" ",STR(this.Value))
this.SelStart=0 &&显示数字类型且表格列不够宽时,点击后会出现空白现象,拉宽列就可以显示出来了
this.SelLength=0
*MESSAGEBOX(STR(nposition))
*this.Format="KTZ"
ENDPROC
ENDDEFINE
[此贴子已经被作者于2025-7-1 22:15编辑过]







