|
帮一个网友调试程序。发现一个问题,以前也遇到过,发现不少人遇到,所以分享一下
就是 imagelist treeview里的KEY是区分大小写的
如果下面的代码中这样写,后面treeview添加图标时 这句:
Set node1 = TreeView1.Nodes.Add(, , "根1", "工厂1", "K1", "K2")
提示运行时错误 35601 未发现元素
img.ListImages.Add 1, "k1, LoadPicture(CurrentProject.Path & "\jia.ico")
img.ListImages.Add 2, "k2", LoadPicture(CurrentProject.Path & "\jian.ico")
改成 大写
img.ListImages.Add 1, "K1", LoadPicture(CurrentProject.Path & "\jia.ico")
img.ListImages.Add 2, "K2", LoadPicture(CurrentProject.Path & "\jian.ico")
就正常了
完整代码如下:
Private Sub Form_Load()
Dim img As ImageList
Dim node1 As Node
Set img = Me.ImageList1.Object
img.ListImages.Add 1, "K1", LoadPicture(CurrentProject.Path & "\jia.ico")
img.ListImages.Add 2, "K2", LoadPicture(CurrentProject.Path & "\jian.ico")
Set TreeView1.ImageList = img
Set node1 = TreeView1.Nodes.Add(, , "根1", "工厂1", "K1", "K2")
Set node1 = TreeView1.Nodes.Add(, , "根2", "工厂2", "K1", "K2")
Set node1 = TreeView1.Nodes.Add("根1", tvwChild, "树杈1", "1车间", "K1", "K2")
Set node1 = TreeView1.Nodes.Add("根2", tvwChild, "树杈21", "1车间", "K1", "K2")
Set node1 = TreeView1.Nodes.Add("根1", tvwChild, "树杈2", "2车间", "K1", "K2")
Set node1 = TreeView1.Nodes.Add("根2", tvwChild, "树杈22", "总装车间", "K1", "K2")
Set node1 = TreeView1.Nodes.Add("树杈1", tvwChild, "树枝1", "手机", "K1", "K2")
Set node1 = TreeView1.Nodes.Add("树杈21", tvwChild, "树枝21", "计算机配件", "K1", "K2")
Set node1 = TreeView1.Nodes.Add("树杈1", tvwChild, "树枝2", "电话", "K1", "K2")
Set node1 = TreeView1.Nodes.Add("树杈2", tvwChild, "树枝3", "手视机", "K1", "K2")
Set node1 = TreeView1.Nodes.Add("树杈2", tvwChild, "树枝4", "洗衣机", "K1", "K2")
Set node1 = TreeView1.Nodes.Add("树杈2", tvwChild, "树枝5", "电冰箱", "K1", "K2")
Set node1 = TreeView1.Nodes.Add("树杈22", tvwChild, "树枝221", "显示器", "K1", "K2")
Set node1 = TreeView1.Nodes.Add("树杈22", tvwChild, "树枝222", "主机", "K1", "K2")
node1.Sorted = True
TreeView1.Style = 5
TreeView1.Font = "宋体"
TreeView1.Appearance = 1
TreeView1.Nodes(1).Expanded = True
End Sub
|
|