| 发表于:2008-01-09 15:22:164楼 得分:0 |
public sub tree_change() '定义添加树状列表的函数 dim key as string, text as string 'string 为字符型。 dim node1 as node, node2 as node, node3 as node '定义一个节点变量。 adodc1.recordsource = "select * from spzl where lbbs='是' order by lbbh asc" '返回一个记录集的查询。 adodc1.refresh 'refresh 方法(ado):更新集合中的对象以便反映来自并特定于提供者的对象。refresh 方法根据从中调用的不同集合而完成不同的任务。 treeview1.nodes.clear '使treeview控件里面的内容清空。不先清空的话,第2遍执行以下代码时就会警告“集合中的关键字不唯一”。 if adodc1.recordset.recordcount > 0 then 'recordcount 属性(ado):指示 recordset 对象中记录的当前数目。返回长整型值。 adodc1.recordset.movefirst '使用 movefirst 方法将当前记录位置移动到 recordset 中的第一个记录。 do while adodc1.recordset.eof = false '如果当前记录位于 recordset 对象的最后一个记录之后,eof 属性将返回 true,而当前记录为 recordset 对象的最后一个记录或位于其前,则将返回 false。 if len(trim(adodc1.recordset.fields("lbbh"))) = 2 then '类别编号 'len 函数:返回 long 长整型,其中包含字符串内字符的数目,或是存储一变量所需的字节数。 'ltrim、rtrim与trim函数:返回variant变体型(string字符型),其中包含指定字符串的拷贝,没有前导空白(ltrim)、尾随空白(rtrim)或前导和尾随空白(trim)。 'fields 集合(ado):fields 集合包含 recordset 对象的所有 field 对象。每个 field 对象对应 recordset 中的一列。 key = "id" & trim(adodc1.recordset.fields("spzlid")) '商品资料id text = trim(adodc1.recordset.fields("lbbh")) & " " & trim(adodc1.recordset.fields("mc")) '类别编号,名称 '& 运算符:用来强制两个表达式作字符串连接。str( '语法:result = expression1 & expression2 'result 部分:必需的;任何 string字符型 或 variant变体型 变量。expression1与expression2部分:必需的;任何表达式。 set node1 = treeview1.nodes.add(, , key, text, 1, 2) 'key值不能用数字开头,不然会弹出警告“无效的关键字”。 'set 语句:将对象引用赋给变量或属性。 'add 方法(nodes 集合):在 treeview 控件的 nodes 集合中添加一个 node 对象。 '语法:object.add(relative, relationship, key, text, image, selectedimage) 'object:必需的。对象表达式,其值是“应用于”列表中的一个对象。 'relative:可选的。已存在的 node 对象的索引号或键值。新节点与已存在的节点间的关系,可在下一个参数 relationship 中找到。 'relationship:可选的。指定的 node 对象的相对位置,如设置值中所述。 'key:可选的。唯一的字符串,可用于用 item 方法检索 node。 'text:必需的。在 node 中出现的字符串。 'image:可选的。在关联的 imagelist 控件中的图像的索引。 'selectedimage:可选的。在关联的 imagelist 控件中的图像的索引,在 node 被选中时显示。 end if if len(trim(adodc1.recordset.fields("lbbh"))) = 4 then key = "id" & trim(adodc1.recordset.fields("spzlid")) text = trim(adodc1.recordset.fields("lbbh")) & " " & trim(adodc1.recordset.fields("mc")) set node2 = treeview1.nodes.add(node1.index, tvwchild, key, text, 1, 2) 'index 属性(split 对象):返回对选定拆分的索引。 'tvwchild 常数:(缺省)子节点。该 node 成为在 relative 中被命名的节点的子节点。 end if if len(trim(adodc1.recordset.fields("lbbh"))) = 6 then key = "id" & trim(adodc1.recordset.fields("spzlid")) text = trim(adodc1.recordset.fields("lbbh")) & " " & trim(adodc1.recordset.fields("mc")) set node3 = treeview1.nodes.add(node2.index, tvwchild, key, text, 1, 2) end if adodc1.recordset.movenext loop end if end sub | | |
|