VB编程:利用二维数组MSHFlexGrid表格添加数据
运行效果:
程序代码:
Private Sub Form_Load()
Dim i, j As Integer
Me.MSHFlexGrid1.Cols = 8
Me.MSHFlexGrid1.Rows = 15
For j = 0 To Me.MSHFlexGrid1.Cols - 1 '从第一列到最后一列遍历循环
Me.MSHFlexGrid1.ColAlignment(j) = 3 '列内容顶部居中
For i = 0 To Me.MSHFlexGrid1.Rows - 1 '从第一行到最后一行遍历循环
Me.MSHFlexGrid1.TextMatrix(i, j) = i * j '单元格的数值等于坐标乘积
Next i
Next j
End Sub
学习心得:
1、添加部件"Microsoft Hierarchical FlexGrid Control 6.0 (OLEDB)"才能使用MSHFlexGrid.
Col:列,Row:行。
Cols:总列数;Rows:总行数。
ColWidth:列宽;RowHeight:行高。
ColAlignment:列对齐;CellAlignment:单元对齐。