运行时候提示:“实时错误 在ImageList可以使用之前必须将它初始化”
不知道问题出在什么地方,希望老师们帮忙看下。
Private Sub FillTreeViewControl(strParentKey As String)
Dim nodX As Node
Dim strImg As String
Dim nCount As Integer, i As Integer
Dim nAttr As Integer
Dim strItem As String
If EnumItemNameBag.Count = 0 And strParentKey = txtServer.Text Then
Set nodX = TreeView1.Nodes.Add(, tvwFirst, txtServer.Text, txtServer.Text, "root") '此行提示错误。
Exit Sub
End If
nCount = EnumItemAttributeBag.Count
If nCount = 0 Then Exit Sub
For i = 1 To nCount
nAttr = EnumItemAttributeBag.Item(i)
strItem = EnumItemNameBag(i)
If nAttr = FILE_ATTRIBUTE_DIRECTORY Then
strImg = "closed"
Else
strImg = "leaf"
End If
Set nodX = TreeView1.Nodes.Add(strParentKey, tvwChild, strParentKey & "/" & strItem, _
strParentKey & "/" & strItem, strImg)
Next
nodX.EnsureVisible
End Sub
6 个解决方案
#1
Set nodX = TreeView1.Nodes.Add(tvwFirst, txtServer.Text, txtServer.Text, "root") '此行提示错误。
#2
直接改成Set nodX = TreeView1.Nodes.Add(,, "root",txtServer.Text) 'root表示key
#3
谢谢你,但是这样之后,又出现了新问题,调试还是没通过:
Private Sub FillTreeViewControl(strParentKey As String)
Dim nodX As Node
Dim strImg As String
Dim nCount As Integer, i As Integer
Dim nAttr As Integer
Dim strItem As String
If EnumItemNameBag.Count = 0 And strParentKey = txtServer.Text Then
Set nodX = TreeView1.Nodes.Add(, , "root", txtServer.Text)
Exit Sub
End If
nCount = EnumItemAttributeBag.Count
If nCount = 0 Then Exit Sub
For i = 1 To nCount
nAttr = EnumItemAttributeBag.Item(i)
strItem = EnumItemNameBag(i)
If nAttr = FILE_ATTRIBUTE_DIRECTORY Then
strImg = "closed"
Else
strImg = "leaf"
End If
Set nodX = TreeView1.Nodes.Add(strParentKey, tvwChild, strParentKey & "/" & strItem, _
strParentKey & "/" & strItem, strImg) Next
nodX.EnsureVisible
End Sub
提示:实时错误 '35601' 未发现元素。
#4
谢谢你,但是这样之后,又出现了新问题,调试还是没通过:
提示:实时错误 '35601' 未发现元素。
Private Sub FillTreeViewControl(strParentKey As String)
Dim nodX As Node
Dim strImg As String
Dim nCount As Integer, i As Integer
Dim nAttr As Integer
Dim strItem As String
If EnumItemNameBag.Count = 0 And strParentKey = txtServer.Text Then
Set nodX = TreeView1.Nodes.Add(, , "root", txtServer.Text)
Exit Sub
End If
nCount = EnumItemAttributeBag.Count
If nCount = 0 Then Exit Sub
For i = 1 To nCount
nAttr = EnumItemAttributeBag.Item(i)
strItem = EnumItemNameBag(i)
If nAttr = FILE_ATTRIBUTE_DIRECTORY Then
strImg = "closed"
Else
strImg = "leaf"
End If
Set nodX = TreeView1.Nodes.Add(strParentKey, tvwChild, strParentKey & "/" & strItem, _strParentKey & "/" & strItem, strImg) '此句提示错误
Next
nodX.EnsureVisible
End Sub
提示:实时错误 '35601' 未发现元素。
#5
谢谢你们,问题解决了,我发现我没有在treeview控件属性把“图像列表”设置成imagelist1
#6
我也遇到过这情况,但是我第一个想到的就是那个问题,应该是你对那控件还不熟悉,多用几次就记住了。
#1
Set nodX = TreeView1.Nodes.Add(tvwFirst, txtServer.Text, txtServer.Text, "root") '此行提示错误。
#2
直接改成Set nodX = TreeView1.Nodes.Add(,, "root",txtServer.Text) 'root表示key
#3
谢谢你,但是这样之后,又出现了新问题,调试还是没通过:
Private Sub FillTreeViewControl(strParentKey As String)
Dim nodX As Node
Dim strImg As String
Dim nCount As Integer, i As Integer
Dim nAttr As Integer
Dim strItem As String
If EnumItemNameBag.Count = 0 And strParentKey = txtServer.Text Then
Set nodX = TreeView1.Nodes.Add(, , "root", txtServer.Text)
Exit Sub
End If
nCount = EnumItemAttributeBag.Count
If nCount = 0 Then Exit Sub
For i = 1 To nCount
nAttr = EnumItemAttributeBag.Item(i)
strItem = EnumItemNameBag(i)
If nAttr = FILE_ATTRIBUTE_DIRECTORY Then
strImg = "closed"
Else
strImg = "leaf"
End If
Set nodX = TreeView1.Nodes.Add(strParentKey, tvwChild, strParentKey & "/" & strItem, _
strParentKey & "/" & strItem, strImg) Next
nodX.EnsureVisible
End Sub
提示:实时错误 '35601' 未发现元素。
#4
谢谢你,但是这样之后,又出现了新问题,调试还是没通过:
提示:实时错误 '35601' 未发现元素。
Private Sub FillTreeViewControl(strParentKey As String)
Dim nodX As Node
Dim strImg As String
Dim nCount As Integer, i As Integer
Dim nAttr As Integer
Dim strItem As String
If EnumItemNameBag.Count = 0 And strParentKey = txtServer.Text Then
Set nodX = TreeView1.Nodes.Add(, , "root", txtServer.Text)
Exit Sub
End If
nCount = EnumItemAttributeBag.Count
If nCount = 0 Then Exit Sub
For i = 1 To nCount
nAttr = EnumItemAttributeBag.Item(i)
strItem = EnumItemNameBag(i)
If nAttr = FILE_ATTRIBUTE_DIRECTORY Then
strImg = "closed"
Else
strImg = "leaf"
End If
Set nodX = TreeView1.Nodes.Add(strParentKey, tvwChild, strParentKey & "/" & strItem, _strParentKey & "/" & strItem, strImg) '此句提示错误
Next
nodX.EnsureVisible
End Sub
提示:实时错误 '35601' 未发现元素。
#5
谢谢你们,问题解决了,我发现我没有在treeview控件属性把“图像列表”设置成imagelist1
#6
我也遇到过这情况,但是我第一个想到的就是那个问题,应该是你对那控件还不熟悉,多用几次就记住了。