我需要遍历数据并为每个设施添加节点到UltraTree对象。但是,当给定设施有多条记录时,它会失败。
系统。ArgumentException:'Key already exists, Key: ts1'
所以我试着检查现有的节点,只添加如果它不已经存在。
'facNode is an UltraTreeNode
'nodeName is a string
If (facNode.Nodes.Contains(nodeName) = False) Then
Dim selectable = facNode.Nodes.Add(nodeName, "Study Director " & studyFacility.SMStudyDirectorName)
[Do Stuff]
End If
不幸的是,facNode.Nodes.Contains(节点名)的计算结果总是false。Visual Studio说,"表达式会导致副作用,不会被求值。">
我发现很多线程/文章都说每个键必须是唯一的,但是我没有找到正确的语法来检查键是否已经存在。
我明白了。它是Exists()方法而不是Contains()。
If (facNode.Nodes.Exists(nodeName) = False) Then