在该方案中,您可以使用 Hierarchical FlexGrid 创建一个大纲样式的显示,该显示带有可以折叠和扩展的标头。
要创建该数据显示,请按照以下步骤执行:
要完成该方案,请按照该部分中的顺序执行下列步骤。
使用 FormatString 属性设置四个列标头。将第一列设置为同其他列一样窄和空(象一个电子表格),以包含数据(包括每个标头间的空间)。此外,还要按照以下设置:
MSHFlexGrid 控件
属性 | 设置值 |
Name | Fg3 |
Cols | 4 |
Rows | 2 |
Selection Mode | 1 – By Row |
FillStyle | 1 – Repeat |
FocusRect | 0 – None |
GridLines | 0 – None |
GridLinesFixed | 2 – Inset |
FormatString | ^ |Description |>Date |>Amount |
FontName | Arial |
使用下列步骤完成该方案,使用 Hierarchical FlexGrid 创建一个带有标头的大纲显示。
要创建带有标头的大纲显示,请按照以下步骤执行:
Sub Form_Load () Dim i As Integer, tot As Integer Dim t As String, s As String '
创建示例数据。t = Chr(9)
Fg3.Rows = 1
Fg3.AddItem "*" + t + "Air Fare"
s = "" +t+ "SFO-JFK" +t+ "9-Apr-95" +t+ "750.00"
For i = 0 to 5
Fg3.AddItem s
Next
Fg3.AddItem "*" + t + "Meals"
s = "" +t+ "Flint's BBQ" +t+ "25-Apr-95" _
+t+ "35.00"
For i = 0 to 5
Fg3.AddItem s
Next
Fg3.AddItem "*" +t+ "Hotel"
s = "" +t+ "Center Plaza" +t+ "25-Apr-95" _
+t+ "817.00"
For i = 0 to 5
Fg3.AddItem s
Next
'
添加总计和格式标头项。For i = Fg3.Rows - 1 To 0 Step -1
If Fg3.TextArray(i * Fg3.Cols) = "" Then
tot = tot + Val(Fg3.TextArray_
(i * Fg3.Cols + 3))
Else
Fg3.Row = i
Fg3.Col = 0
Fg3.ColSel = Fg3.Cols - 1
Fg3.CellBackColor = &HC0C0C0
Fg3.CellFontBold = True
Fg3.CellFontWidth = 8
Fg3.TextArray(i * Fg3.Cols + 3) = _
Format(tot, "0")
tot = 0
End If
Next
Fg3.ColSel = Fg3.Cols - 1
'
格式化网格Fg3.ColWidth(0) = 300
Fg3.ColWidth(1) = 1500
Fg3.ColWidth(2) = 1000
Fg3.ColWidth(3) = 1000
End Sub
运行时,将行按其标头(Air Fare、Meals 和 Hotels)分成三部分,如下图所示:
Sub Fg3_DblClick () Dim i As Integer, r As Integer '
忽略顶端的行。r = Fg3.MouseRow
If r < 1 Then Exit Sub
'
查找要折叠或扩充的字段。While r > 0 And Fg3.TextArray(r * Fg3.Cols) = ""
r = r - 1
Wend
'
在第一列显示折叠/
扩充符号图。If Fg3.TextArray(r * Fg3.Cols) = "*" Then
Fg3.TextArray(r * Fg3.Cols) = "+"
Else
Fg3.TextArray(r * Fg3.Cols) = "*"
End If
'
在当前标头下扩充项目。r = r + 1
If Fg3.RowHeight(r) = 0 Then
Do While Fg3.TextArray(r * Fg3.Cols) = ""
Fg3.RowHeight(r) = -1' Default row height.
r = r + 1
If r >= Fg3.Rows Then Exit Do
Loop
'
在当前标头下折叠项目。Else
Do While Fg3.TextArray(r * Fg3.Cols) = ""
Fg3.RowHeight(r) = 0
'
隐藏行。r = r + 1
If r >= Fg3.Rows Then Exit Do
Loop
End If
End Sub
一旦该方案中的所有步骤都完成,您就可以在运行时通过双击第一列中的符号 "+" 或 "*" 来展开或折叠行标头,如下例所示:
注意 很容易改动此例,使之显示图象而不是 "+" 和 "*" 字符,或者在概要中添加附加的层次。