listview中列的个数有限制吗?
我用listview显示数据库里的数据,下面是一部分代码。
Dim rs1 As ADODB.Recordset
Set rs1 = New ADODB.Recordset
Dim i As Integer
rs1.Open si, conn, 1, 1
Do While Not rs1.EOF
Set addlist = ListView1.ListItems.Add
addlist.SubItems(0) = IIf(IsNull(rs1.Fields("资产标志").Value), "", rs1.Fields("资产标志").Value)
addlist.SubItems(1) = IIf(IsNull(rs1.Fields("资产编号").Value), "", rs1.Fields("资产编号").Value)
addlist.SubItems(2) = IIf(IsNull(rs1.Fields("资产名称").Value), "", rs1.Fields("资产名称").Value)
addlist.SubItems(3) = IIf(IsNull(rs1.Fields("品名").Value), "", rs1.Fields("品名").Value)
addlist.SubItems(4) = IIf(IsNull(rs1.Fields("生产厂家").Value), "", rs1.Fields("生产厂家").Value)
addlist.SubItems(5) = IIf(IsNull(rs1.Fields("型号").Value), "", rs1.Fields("型号").Value)
addlist.SubItems(6) = IIf(IsNull(rs1.Fields("配置").Value), "", rs1.Fields("配置").Value)
addlist.SubItems(7) = IIf(IsNull(rs1.Fields("数量").Value), "", rs1.Fields("数量").Value)
addlist.SubItems(8) = IIf(IsNull(rs1.Fields("购进单位").Value), "", rs1.Fields("购进单位").Value)
addlist.SubItems(9) = IIf(IsNull(rs1.Fields("使用人").Value), "", rs1.Fields("使用人").Value)
Text2.Text = Text2.Text + Val(rs1.Fields("数量").Value)
rs1.MoveNext
Loop
rs1.close
conn.close
我执行的时候,addlist.SubItems(0) = IIf(IsNull(rs1.Fields("资产标志").Value), "", rs1.Fields("资产标志").Value)这句会出现错误:无效的属性值。
[解决办法]
如果控件总共有十列,且"资产标志"作为第一列的内容,则如4楼,亦可Set addlist = ListView1.ListItems.Add
addlist.text=rs("资产标志") &""
addlist.SubItems(1) = rs1("资产编号) &""
....
控件上点右键,设置列数
也可以listview.columnheaders.add添加列