
以下為實(shí)現(xiàn)該效果的完整代碼:
*-- 程序功能:創(chuàng)建一個(gè)含有樹形分支的表格
* 作者:紅虎(honghoo.net)
* 日期:2002.8.3
*-- 所需控件 vsFlex7.ocx
* 調(diào)試環(huán)境:vfp7+pwin98se
With thisform.VSFlexGrid
.Subtotal(0) && 清除表格匯總
.Cols = 5 && 設(shè)置列數(shù)
.Rows = 1 + 5^4 && 設(shè)置行數(shù) 注:從第零行開始
.FixedRows = 1 && 設(shè)置固定行數(shù) (第零行)
.FixedCols = 1 && 設(shè)置固定列數(shù) (第零列)
.ColWidth(0) = 0 && 設(shè)置第一列的寬度為零
.Clear && 清除表格中的數(shù)據(jù)。
.AllowUserResizing = 1 && flexResizeColumns 只允許調(diào)整列寬
.OutlineBar = 1 && 左邊樹型的樣式,顯示分層數(shù)和線條
.OutlineCol = 0 && 在哪列顯示分層
.MergeCells= 7 && flexMergeOutline 合并方式
*-- 設(shè)定標(biāo)題行的四個(gè)標(biāo)題
.TextMatrix(0, 1) = "第一層"
.TextMatrix(0, 2) = "第二層"
.TextMatrix(0, 3) = "第三層"
.TextMatrix(0, 4) = "顯示數(shù)據(jù)"
LOCAL a,b,c,d,r
STORE 0 TO a,b,c,d,r
*-- 設(shè)置三層循環(huán),加載數(shù)據(jù)
r = 0
FOR a=1 TO 5
FOR b=1 TO 5
FOR c=1 TO 5
FOR d=1 TO 5
r = r + 1
.TextMatrix(r,1) = "a" + ALLTRIM(STR(a))
.TextMatrix(r,2) = "a" + ALLTRIM(STR(a)) + "b" + ALLTRIM(STR(b))
.TextMatrix(r,3) = "a" + ALLTRIM(STR(a)) + "b" + ALLTRIM(STR(b)) + "c" + ALLTRIM(STR(c))
.TextMatrix(r,4) = ""
ENDFOR
ENDFOR
ENDFOR
ENDFOR
*-- 進(jìn)行數(shù)據(jù)匯總,但是不匯總!第一個(gè)參數(shù)就是不統(tǒng)計(jì),只是為了顯示樹
* 第二個(gè)參數(shù)是列數(shù),后面是前景,背景色,以及是否用粗體
.Subtotal(0, 1,,, RGB(255,0,0), RGB(255, 255, 255), .T.)
.Subtotal(0, 2,,, RGB(128, 128, 128), RGB(0, 255, 0), .T.)
.Subtotal(0, 3,,, RGB(128, 128, 200), RGB(255, 255, 255), .T.)
EndWith