Link to home
Start Free TrialLog in
Avatar of rite_eh
rite_eh

asked on

Treeview key node test

Hello,

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).

Ex:
if treeView.Nodes("key-to-check") is nothing then
 ' add the node
else
 msgbox "Error, key-to-check already exists."
end if

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.
ASKER CERTIFIED SOLUTION
Avatar of ChloesDad
ChloesDad
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rite_eh
rite_eh

ASKER

This is a .net solution, but I am writing in both so good enough for me.

Thanks