I am trying to come up with a way to test is a key is already present in a treeview before I add a node. My treeview is populated from a flat file and it is possible (though unlikely) that the file could contain duplicate records. If this is the case I would like to notify the user via a MsgBox of the duplicate. Currently the duplicates are caught by a standard error handler that traps the 35602 - key is not unique in collection message. However I would like to test for a duplicate before the new node is added (and fails).
if treeView.Nodes("key-to-check") is nothing then
' add the node
msgbox "Error, key-to-check already exists."
Currently when I try to use this method I receive a different runtime error, something relating to the node could not be found. My node keys are not something I am willing to change as they are referenced in many places.
Is there a way I can check to see if a node with a specific key already exists without having to trap an error?
Thanks in advance for any and all suggestions.