Sub OnClick(Byval Item)
Dim TV,CD,FileName,objxml,i,Element
Set TV=ScreenItems("TV")
Set CD=ScreenItems("CD")
Set objxml=Createobject("MSXML2.DOMDocument")
CD.Filter="*.xml|*.xml"
CD.FilterIndex=20
CD.ShowOpen
FileName=CD.FileName
TV.nodes.clear
Call objxml.load (FileName)
For i=0 To objxml.getElementsByTagName ("NODE").length-1
Set Element = objxml.getElementsByTagName ("NODE").Item(i)
If Element.getAttribute("ParentKey") =""Then
TV.Nodes.Add,,Element.getAttribute("Key"),Element.getAttribute("Caption")
Else
TV.Nodes.Add Element.getAttribute("ParentKey"),4,Element.getAttribute("Key"),Element.getAttribute("Caption")
End If
Next
For i=1 To TV.nodes.count
If TV.nodes.item(i).Children>0 Then
TV.Nodes(i).Expanded=True
End If
Next
TV.Nodes(1).Selected=True
TV.Nodes(1).EnsureVisible
TV.Style =6
TV.LineStyle =1
End Sub
最佳答案
名为CD的控件是CommonDialog,删除弹出对话框的代码,设置TV的Load方法为指定路径即可。
Sub OnClick(Byval Item)
Dim TV,CD,FileName,objxml,i,Element
Set TV=ScreenItems("TV")
Set CD=ScreenItems("CD") ''删除
Set objxml=Createobject("MSXML2.DOMDocument")
CD.Filter="*.xml|*.xml" ''删除
CD.FilterIndex=20 ''删除
CD.ShowOpen ''删除
FileName=CD.FileName ''设置指定路径如"c:\tmp\test.xml"
TV.nodes.clear
提问者对于答案的评价:
太谢谢你了,问题解决。
原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc173222.html