Solved

Treeview key node test

Posted on 2009-05-06
2
359 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 15

Accepted Solution

by:
ChloesDad earned 500 total points
ID: 24320516
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
ID: 24320788
This is a .net solution, but I am writing in both so good enough for me.

Thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…

695 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