放两个command button,一个MSFlexGrid到一个新建窗体,全部用缺省名字。粘贴下面的代码。第一个按钮使第1行局中,第2个使所有列局中。
Private Sub Command1_Click()
Dim i, iCols As Integer
iCols = MSFlexGrid1.Cols
MSFlexGrid1.Row = 0
For i = 0 To iCols - 1
MSFlexGrid1.Col = i
MSFlexGrid1.CellAlignment = flexAlignCenterCenter
Next
End Sub
Private Sub Command2_Click()
Dim i, iCols As Integer
iCols = MSFlexGrid1.Cols
For i = 0 To iCols - 1
MSFlexGrid1.ColAlignment(i) = flexAlignCenterCenter
Next
End Sub
Private Sub Form_Load()
Dim i As Integer, n As Integer
MSFlexGrid1.Cols = 4
MSFlexGrid1.Rows = 4
For i = 1 To 4
For n = 1 To 4
MSFlexGrid1.TextMatrix(i - 1, n - 1) = i * n
Next
Next
'put some value with different type
MSFlexGrid1.TextMatrix(0, 1) = "month"
MSFlexGrid1.TextMatrix(0, 2) = "date"
MSFlexGrid1.TextMatrix(1, 1) = "a"
MSFlexGrid1.TextMatrix(3, 3) = "b"
End Sub
如果上面的是所有行都局中,如果只针对第一行的话,这个:
Dim i, iCols As Integer
iCols = MSFlexGrid1.Cols
For i = 0 To iCols - 1
MSFlexGrid1.Col = i
MSFlexGrid1.CellAlignment = flexAlignCenterCenter
Next