Solved

Treeview key node test

Posted on 2009-05-06
2
342 Views
Last Modified: 2012-05-06
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.
0
Comment
Question by:rite_eh
2 Comments
 
LVL 15

Accepted Solution

by:
ChloesDad earned 500 total points
Comment Utility
The easiest way is using the containskey function of a treeview

so assuming that a node was added using

dim primaryNode as treenode= New TreeNode(sometext)
                Me.TreeView1.Nodes.Add(primaryNode)

Then you can see if a node already exists using

if TreeView1.Nodes.ContainsKey(sometext) then

    msgbox "Error, key-to-check already exists."

else

  ' add the node

endif
0
 
LVL 1

Author Comment

by:rite_eh
Comment Utility
This is a .net solution, but I am writing in both so good enough for me.

Thanks
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now