标准答案来了Private Sub Command1_Click() Dim a(12) As Long Dim i As Long, j As Long With Grid1 a(0) = Grid1.Column(0).Width + Grid1.Column(1).Width Me.Caption = Me.Caption & ",a(0)=" & a(0) For i = 1 To 11 a(i) = a(i - 1) + .Column(i + 1).Width Me.Caption = Me.Caption & ",a(" & i & ")=" & a(i) Next End With End Sub
dim j as interfor i=0 to 11
for j=0 to i+1
a(i)=a(i)+Grid1.Column(j).Width
next
next思路是这样的,代码自已整理一下,应该可以!
qiwen1530 不对哦 所赋值不正确 赋值后 无法退出
我的意思是
a(0)=Grid1.Column(0).Width+Grid1.Column(1).Width
a(1)=a(0)+Grid1.Column(2).Width
a(2)=a(1)+Grid1.Column(3).Width
a(3)=a(2)+Grid1.Column(4).Width
......
a(11)=a(10)+Grid1.Column(12).Width就是加上上已列的列宽值
Dim a(12) As Long
Dim i As Long, j As Long
With Grid1
a(0) = Grid1.Column(0).Width + Grid1.Column(1).Width
Me.Caption = Me.Caption & ",a(0)=" & a(0)
For i = 1 To 11
a(i) = a(i - 1) + .Column(i + 1).Width
Me.Caption = Me.Caption & ",a(" & i & ")=" & a(i)
Next
End With
End Sub