【问题标题】:How to check if an UltraTree node already exists如何检查 UltraTree 节点是否已存在
【发布时间】:2021-05-15 12:58:18
【问题描述】:

我需要遍历数据并将节点添加到每个设施的 UltraTree 对象。但当给定设施有多个记录时,它会失败。

System.ArgumentException: '密钥已存在,密钥: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(nodeName) 总是评估为假。 Visual Studio 说,“表达式会产生副作用,不会被计算。”

我发现许多线程/文章说每个键必须是唯一的,但我无法找到正确的语法来检查键是否已经存在。

【问题讨论】:

    标签: vb.net ultratree


    【解决方案1】:

    我想通了。它是 Exists() 方法而不是 Contains()。

    If (facNode.Nodes.Exists(nodeName) = False) Then

    【讨论】:

      猜你喜欢
      • 2019-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-03
      • 2011-04-16
      • 1970-01-01
      • 2021-08-16
      相关资源
      最近更新 更多