不是难不难理解,而是思路,处理同样一件事,我用的思路和你用的思路差别太大了。
改一下如下的代碼,可適應無過濾條件(此時調用Grid1.Init事件不傳入參數即可)的情形:
程序代码:
PROCEDURE Grid1.Init(tcFilter AS Character) LOCAL laColumns[5+RECCOUNT("kcb"),5] LOCAL lnIndex AS Integer laColumns[1,1] = "学号" laColumns[1,2] = "xsb.xh" laColumns[1,3] = 100 laColumns[2,1] = "姓名" laColumns[2,2] = "xsb.xm" laColumns[2,3] = 60 laColumns[3,1] = "班级名称" laColumns[3,2] = "xsb.bjmc" laColumns[3,3] = 60 laColumns[4,1] = "总成绩" laColumns[4,2] = "Get_TotalScore(xsb.xh)" laColumns[4,3] = 80 laColumns[4,4] = "Z" laColumns[4,5] = "99,999.99" laColumns[5,1] = "平均分" laColumns[5,2] = "Get_AverageScore(xsb.xh)" laColumns[5,3] = 80 laColumns[5,4] = "Z" laColumns[5,5] = "999.99" GOTO TOP IN kcb lnIndex = 5 DO WHILE !EOF("kcb") lnIndex = lnIndex + 1 laColumns[lnIndex,1] = ALLTRIM(kcb.kcm) laColumns[lnIndex,2] = "Get_Score(xsb.xh, '" + kcb.kch + "')" laColumns[lnIndex,3] = 80 laColumns[lnIndex,4] = "Z" laColumns[lnIndex,5] = "999.99" SKIP IN kcb ENDDO WITH This IF (PCOUNT() == 1) .AND. (VARTYPE(tcFilter) == "C") SET FILTER TO &tcFilter IN xsb ELSE SET FILTER TO IN xsb ENDIF .Set_Columns(@laColumns, "xsb") .ReadOnly = .T. .LockColumns = 3 .HeaderHeight = 35 .RowHeight = 25 ENDWITH WITH This lnIndex = 5 DO WHILE lnIndex <= .ColumnCount WITH .Columns(lnIndex).Header1 IF LENC(.Caption) > 5 .Caption = Wrap_String(.Caption, 5) .WordWrap = .T. ENDIF ENDWITH lcString = .Columns(lnIndex).ControlSource LOCAL lcSum AS Number SUM &lcString ALL TO lnSum IF lnSum > 0 lnIndex = lnIndex + 1 ELSE .DeleteColumn(lnIndex) ENDIF ENDDO ENDWITH GOTO TOP IN xsb ENDPROC
[ 本帖最后由 TonyDeng 于 2011-7-17 12:44 编辑 ]