所以,我试图按照this指南从Visual Basic中的XML数据填充树视图,但它会抛出错误:
"重载解析失败,因为没有可访问的'项目'可 在没有缩小转换的情况下调用: ' Public Overridable ReadOnly默认属性项(键为字符串)As System.Windows.Forms.TreeNode&#39 ;:参数匹配参数'键' 来自“龙”的缩小to' String'。 ' Public Overridable默认属性项(索引为整数)As System.Windows.Forms.TreeNode&#39 ;:参数匹配参数' index' 来自“龙”的缩小到'整数'。"
经过一番搜索,我被告知将Option Strict设置为" Off"会解决错误,但它没有做到这一点。有没有人有这个错误的解决方案?
以下是相关代码:
If inXmlNode.HasChildNodes() Then
nodeList = inXmlNode.ChildNodes
For i = 0 To nodeList.Count - 1
xNode = inXmlNode.ChildNodes(i)
inTreeNode.Nodes.Add(New TreeNode(xNode.Name))
tNode = inTreeNode.Nodes(i)
AddNode(xNode, tNode) //The code that throws the error.
Next
Else
' Here you need to pull the data from the XmlNode based on the
' type of node, whether attribute values are required, and so forth.
inTreeNode.Text = (inXmlNode.OuterXml).Trim
End If
答案 0 :(得分:0)
将i定义为整数而不是长整数。它应该匹配过载。
Private Sub AddNode(ByRef inXmlNode As XmlNode, ByRef inTreeNode As TreeNode)
Dim xNode As XmlNode
Dim tNode As TreeNode
Dim nodeList As XmlNodeList
Dim i As Integer
If inXmlNode.HasChildNodes() Then
nodeList = inXmlNode.ChildNodes
For i = 0 To nodeList.Count - 1
xNode = inXmlNode.ChildNodes(i)
inTreeNode.Nodes.Add(New TreeNode(xNode.Name))
tNode = inTreeNode.Nodes(i)
AddNode(xNode, tNode) //The code that throws the error.
Next
Else
' Here you need to pull the data from the XmlNode based on the
' type of node, whether attribute values are required, and so forth.
inTreeNode.Text = (inXmlNode.OuterXml).Trim
End If