展开全部
Dim CurLen As Single
Dim MaxLen As Single
Dim i As Integer
Dim CellLen(0 To 9) As Single
Dim tt(0 To 9) As Single '这里多一个数组,用来存放各列的临时宽度。
'SqlStr1 = "select * from dbo.代码 where " & TjDm & TjPh & TjXh & TjDw
'Set rs1 = cn1.Execute(SqlStr1)
If Not Rs1.EOF Then
Rs1.MoveFirst '这句没什么用,可以留着,可以删了。
'标题宽度先存储在宽度数组里。以下要对比判断用。
For i = 0 To Rs1.Fields.Count - 1
CellLen(i) = LenB(StrConv(CStr(Rs1.Fields(i).Name), vbFromUnicode)) * 120
Next
Do While Not Rs1.EOF
For i = 0 To Rs1.Fields.Count - 1
tt(i) = LenB(StrConv(Trim(CStr(Rs1(i).Value)), vbFromUnicode)) * 120
If tt(i) > CellLen(i) Then CellLen(i) = tt(i) '留下大的数字。
Next
Rs1.MoveNext
Loop
Set DataGrid2.DataSource = Rs1
For i = 0 To Rs1.Fields.Count - 1
DataGrid2.Columns(i).Width = CellLen(i)
Next
End If
给你代码,你看看思路。自己改一下代码。
Dim MaxLen As Single
Dim i As Integer
Dim CellLen(0 To 9) As Single
Dim tt(0 To 9) As Single '这里多一个数组,用来存放各列的临时宽度。
'SqlStr1 = "select * from dbo.代码 where " & TjDm & TjPh & TjXh & TjDw
'Set rs1 = cn1.Execute(SqlStr1)
If Not Rs1.EOF Then
Rs1.MoveFirst '这句没什么用,可以留着,可以删了。
'标题宽度先存储在宽度数组里。以下要对比判断用。
For i = 0 To Rs1.Fields.Count - 1
CellLen(i) = LenB(StrConv(CStr(Rs1.Fields(i).Name), vbFromUnicode)) * 120
Next
Do While Not Rs1.EOF
For i = 0 To Rs1.Fields.Count - 1
tt(i) = LenB(StrConv(Trim(CStr(Rs1(i).Value)), vbFromUnicode)) * 120
If tt(i) > CellLen(i) Then CellLen(i) = tt(i) '留下大的数字。
Next
Rs1.MoveNext
Loop
Set DataGrid2.DataSource = Rs1
For i = 0 To Rs1.Fields.Count - 1
DataGrid2.Columns(i).Width = CellLen(i)
Next
End If
给你代码,你看看思路。自己改一下代码。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询