有时列名只有两个字,但是列中内容的字却很多,比如:部门列,有可能会有七八个或是十几个字,而合同结束时间,列名长,而内容却只有八位,那么,如何让系统自动根据情况选择列宽呢?如列名小于内容的宽度,就选内容的宽度,而如果内容小于列名,就选列名的宽度?
主要是用在窗口的表中
[此贴子已经被作者于2010-3-15 13:22:07编辑过]
MaxLength
如果是字符列,返回该列允许输入的最大长度,否则返回-1。
例如:
Dim
Len As Integer
Len = DataTables("订单").DataCols("产品").MaxLength
Output.Show(Len)
Dim Len As Integer
with currenttable
For Each c As Col In CurrentTable.Cols
len = datatables(currenttable.name).datacols(c.name).maxlength
Output.Show(c.Index & " " & c.name & " " & len )
next
end with这个就是列设置时的允许最大的字符数啊。列宽用Width取得吧。
这样都有了::::
Dim Len As Integer
Dim n As Integer
Dim s as string
with currenttable
For Each c As Col In CurrentTable.Cols
len = datatables(currenttable.name).datacols(c.name).maxlength
s = currenttable.Cols(n).Width
Output.Show(c.Index & " " & c.name & " " & len & " => " & s)
''' (列序号 列名 列设置的字符长 列宽度)
n = n + 1
next
end with
[此贴子已经被作者于2010-3-15 14:21:24编辑过]
这个更全啦: 如果都是字符型的列:
Dim Len As Integer
Dim n As Integer
Dim n0 As Integer
Dim s as string
with currenttable
For Each c As Col In CurrentTable.Cols
len = datatables(currenttable.name).datacols(c.name).maxlength
s = currenttable.Cols(n).Width
for i as integer = 0 to currenttable.count -1
if currenttable.rows(i)(c.name).length > n0
n0 = currenttable.rows(i)(c.name).length
end if
next
Output.Show("【列位置: 】" & c.Index & " 【列名:】 " & _
c.name & " 【列设置的字符长度:】 " & len & " 【列宽:】 " & _
s & " 【本列已输入的最大字符长:】 " & n0)
n = n + 1
next
end with
[此贴子已经被作者于2010-3-15 14:51:40编辑过]
还是无法比较,因为maxlength只对字符型有效
谢谢老师!
[此贴子已经被作者于2010-3-15 15:29:33编辑过]
我只能是先这样做了:
Dim n,len As Integer
Dim s As Integer
For Each cl As DataCol In DataTables("RS_统计查询_Table2").DataCols
len = datatables("RS_统计查询_Table2").datacols(cl.name).maxlength
s = Tables("RS_统计查询_Table2").Cols(n).PrintWidth
If cl.name.Length < Math.Abs(len)
Tables("RS_统计查询_Table2").Cols(n).PrintWidth = Math.Abs(len)
Else
Tables("RS_统计查询_Table2").Cols(n).PrintWidth = cl.name.Length *5
End If
n = n + 1
Next