下面这个按钮事件,会把列标题(测试1,测试2)也变成平面的(即和其它记录项一样)!
请问:为什么???Private Sub Command1_Click()
Dim sTitle As String sTitle = "测试1|测试2"
mshfgridTest.FormatString = sTitle Dim sql As String
Dim rst As New ADODB.Recordset
sql = "select * from test表"
rst.LockType = adLockOptimistic
rst.CursorType = adOpenDynamic
rst.Open sql, g_cnn, , , adCmdText
With mshfgridTest
.Rows = 1
Do While Not rst.EOF
.Rows = .Rows + 1
.CellAlignment = 4
.TextMatrix(.Rows - 1, 0) = rst.Fields(0)
.TextMatrix(.Rows - 1, 1) = rst.Fields(1)
rst.MoveNext
Loop
End With
rst.Close
End Sub
请问:为什么???Private Sub Command1_Click()
Dim sTitle As String sTitle = "测试1|测试2"
mshfgridTest.FormatString = sTitle Dim sql As String
Dim rst As New ADODB.Recordset
sql = "select * from test表"
rst.LockType = adLockOptimistic
rst.CursorType = adOpenDynamic
rst.Open sql, g_cnn, , , adCmdText
With mshfgridTest
.Rows = 1
Do While Not rst.EOF
.Rows = .Rows + 1
.CellAlignment = 4
.TextMatrix(.Rows - 1, 0) = rst.Fields(0)
.TextMatrix(.Rows - 1, 1) = rst.Fields(1)
rst.MoveNext
Loop
End With
rst.Close
End Sub
mshfgridTest.FormatString = sTitle
換成:
mshfgridtest.textmatrix(0,0)="测试1"
mshfgridtest.textmatrix(0,1)="测试2"
.ColAlignment(0) = 4
.ColAlignment(1) = 4
Do Until rst.EOF
.AddItem rst.Fields(0) & vbTab & rst.Fields(1)
rst.MoveNext
Loop
End With
.Rows = 2
Do While Not rst.EOF
if .Rows>1 then
.Rows = .Rows + 1
.CellAlignment = 4
.TextMatrix(.Rows - 1, 0) = rst.Fields(0)
.TextMatrix(.Rows - 1, 1) = rst.Fields(1)
rst.MoveNext
end if
Loop
End With
rst.Close这样就行了,楼主你必须要MSHFlexGrid保持有2行,如果有1行的话就自动省略列头了(也就是说,MSHFlexGrid在只有一行的情况下会默认成是行里的内容)
rs.Close
Exit Sub
End If
Do Until rs.EOF
If Not (flcf.Rows = 2 And Trim(flcf.TextMatrix(1, 1)) = "") Then
flcf.AddItem ""
End If
flcf.TextMatrix(flcf.Rows - 1, 0) = rs.Fields!cfid
flcf.TextMatrix(flcf.Rows - 1, 1) = Trim(rs.Fields!JPBWMC)
flcf.TextMatrix(flcf.Rows - 1, 2) = Trim(rs.Fields!QCBWMC)
flcf.TextMatrix(flcf.Rows - 1, 3) = Trim(rs.Fields!TXM)
flcf.TextMatrix(flcf.Rows - 1, 4) = rs.Fields!id
flcf.TextMatrix(flcf.Rows - 1, 5) = rs.Fields!JPBWBH
rs.MoveNext
Loop
rs.Close这是我写的一个,你参考一下还有上一楼那个帖了
With mshfgridTest
.Rows = 2
Do While Not rst.EOF
if .Rows<>2 then
.Rows = .Rows + 1
end if
.CellAlignment = 4
.TextMatrix(.Rows - 1, 0) = rst.Fields(0)
.TextMatrix(.Rows - 1, 1) = rst.Fields(1)
rst.MoveNext
Loop
End With
rst.Close