我怎么知道TreeView是否有TreeNodes,无论它们是父节点还是子节点?我只是想避免重复。伪代码如下:
If TreeView1 has TreeNodes Then
'Remove old ones and create another
'Or Exit to skep creation of new ones
Else
'Create TreeNodes
End Sub
答案 0 :(得分:2)
您可以检查TreeView1.Nodes.Count,或者只需调用TreeView1.Nodes.Clear()以确保在添加新的之前它始终清除
更新以获得更完整的答案:
If TreeView1.Nodes.Count = 0 Then
'Remove old ones and create another
'Or Exit to skep creation of new ones
Else
'Create TreeNodes
End Sub