程序代码:
CLEAR ALL
SET PROCEDURE TO "D:\Projects\MyTools\MyTools"
CLEAR
Main()
CLEAR ALL
RETURN
PROCEDURE Main()
LOCAL loForm
loForm = CREATEOBJECT("_Form")
WITH loForm
.Caption = "Grid test"
.WindowState = 2
.Show
ENDWITH
READ EVENTS
ENDPROC
DEFINE CLASS _DataEnvironment AS DataEnvironment
AutoOpenTables = .T.
AutoCloseTables = .T.
PROCEDURE OpenTables
USE "D:\Projects\test\vfp\dz\data\d.dbf" ALIAS table1 IN 0
ENDPROC
PROCEDURE CloseTables
USE IN table1
ENDPROC
ENDDEFINE
DEFINE CLASS _Form AS myForm
DEClassLibrary = "test7.prg"
DEClass = "_DataEnvironment"
ADD OBJECT Grid1 AS Grid WITH HighlightStyle = 2
PROCEDURE Arrange
WITH This.Grid1
.Top = 5
.Left = 5
.Height = ThisForm.Height - .Top - 5
.Width = ThisForm.Width - .Left - 5
ENDWITH
ENDPROC
PROCEDURE Grid1.Init
WITH This
.AddColumn(1)
WITH .Columns(.ColumnCount)
WITH .Header1
.Caption = "No."
.Alignment = 2
ENDWITH
.ControlSource = "ThisForm." + This.Name + ".ActiveRow"
.Alignment = 2
.Enabled = .F.
.AutoFit()
ENDWITH
.SetAll("FontBold", .T., "Header")
ENDWITH
ENDPROC
ENDDEFINE
把代碼中的表名修改為你需要的表即可。這是從控件著手解決的,不變動數據,是正路。這代碼照抄是運行不出來的,因為沒給全源代碼(缺了MyTools.PRG),只要看懂了,自然知道是怎麼回事——關鍵就是Grid控件的Init事件設置。
[
本帖最后由 TonyDeng 于 2013-12-26 21:23 编辑 ]