'*********************************
'表头居中显示-正确写法
'------------
Private Sub DrawerGrid()
With MSHFlexGrid1
.BackColor = &HFFC0C0
.BackColorSel = &HC0E0FF
.ForeColor = &HC00000
.ForeColorSel = &HC00000
.Cols = 6
.Rows = 2
.ColWidth(0) = 500
.ColWidth(1) = 600
.ColWidth(2) = 1700
.ColWidth(3) = 900
.ColWidth(4) = 600
.ColWidth(5) = 700
.TextMatrix(0, 0) = "序号"
.TextMatrix(0, 1) = "编号"
.TextMatrix(0, 2) = "名称"
.TextMatrix(0, 3) = "规格"
.TextMatrix(0, 4) = "单位"
.TextMatrix(0, 5) = "单价"
'*****************************************************
'关键之处|
'---------
.Row = 0
For i = 0 To .Cols - 1
.Col = i
.CellAlignment = flexAlignCenterCenter '居中对齐
Next i
.Row = 1
Call LoadData '载入数据
'*****************************************************
End With
End Sub
以上显示为:
(图一)
错误写法一.
如果将“关键之处” 的
.Row=0 去掉,即改写为:
'*****************************************************
'关键之处|
'---------
For i = 0 To .Cols - 1
.Col = i
.CellAlignment = flexAlignCenterCenter '居中对齐
Next i
.Row = 1
Call LoadData '载入数据
'*****************************************************
或者将“关键之处”的
.Row=0 和.Row=1一起去掉,即改写为:
'*****************************************************
'关键之处|
'---------
For i = 0 To .Cols - 1
.Col = i
.CellAlignment = flexAlignCenterCenter '居中对齐
Next i
Call LoadData '载入数据
'*****************************************************
那么则显示为第二行居中,表头没有居中:
(图二)
错误写法二.
如果将“关键之处” 的
.Row=1 去掉,即改写为:
'*****************************************************
'关键之处|
'---------
.Row=0
For i = 0 To .Cols - 1
.Col = i
.CellAlignment = flexAlignCenterCenter '居中对齐
Next i
Call LoadData '载入数据
'*****************************************************
那么则显示为表头居中,但却把第一行第二行选中了:
(图三)
正确写法二.
如果将“关键之处” 的
改写为:
'*****************************************************
'关键之处|
'---------
Call LoadData '载入数据
.Row=0
For i = 0 To .Cols - 1
.Col = i
.CellAlignment = flexAlignCenterCenter '居中对齐
Next i
.Row = 1
'*****************************************************
只要保留.Row=0,有没有.Row=1都可正确显示
显示图和(图一)一样