所以,我正在尝试遵循本指南,以填充Visual Basic中XML数据的treeview,但它引发了错误:
"超载分辨率失败了,因为无法访问的'项目'可以是 被称为不缩小转换的情况: '公共可读性默认默认属性项目(键as string)as system.windows.forms.treenode':参数匹配参数'键' 从"长"到"字符串"。 "公共默认默认属性项目(index as integer)为system.windows.forms.treenode':参数匹配参数'index' 从"长"到"整数"。
搜索了一些搜索后,有人告诉我,设置选项严格以"关闭"可以解决该错误,但没有这样做。有人可以解决此错误吗?
这是所讨论的代码:
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
将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