Important alert: (current site time 7/15/2013 9:18:52 AM EDT)
 

winzip icon

TreeView Interface (Drag and Drop; Add, Rename, and Delete Nodes; Save Tree to Database) (Updated)

Email
Submitted on: 11/2/2002 12:53:44 AM
By: Mark E. Thorogood 
Level: Intermediate
User Rating: By 26 Users
Compatibility: VB.NET
Views: 88915
 
     The following program is an example of a Treeview interface. The example demonstrates how to program drag and drop; add, delete, and rename nodes; saving a tree to a database; and restoring a tree from a database. When you first run the program, you will be presented with a form that will ask you to locate or use a database file. You must use "TreeViewEx.mdb", which is included with the project. You may have to navigate to locate this file. This update corrects two unhandled exceptions (one occurring when attempting to delete the direct child of a root node). The program also demonstrates how to separate data services into its own class. Please see the text file included with the solution for a complete list of functions. There are some pretty nifty ones. Please feel free to e-mail me if you have any questions (mthorogood@mwe.com). Enjoy.
 
winzip iconDownload code

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come out every day, so no prevention program can catch 100% of them. For your own safety, please:
  1. Re-scan downloaded files using your personal virus checker before using it.
  2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

If you don't have a virus scanner, you can get one at many places on the net including:McAfee.com

 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.


Other 1 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
11/8/2002 1:56:12 PM

Terrific submission - Thanks very much for such thouroughly and clearly documented code. I learned a lot, not just about the TreeView, but recognized some vb.net best-practices that I will be revising my own current project to follow. - Thanks very much for such a useful submission!
(If this comment was disrespectful, please report it.)

 
11/20/2002 7:29:34 AM

This code is excellent and help me a lot, really appreciate the author share the code to us. Thanks!
(If this comment was disrespectful, please report it.)

 
12/13/2002 2:25:34 PM

I found exactly what I wanted in this program such as how to save a tree structure into a database and how to drag and drop nodes in a treeview. Thanks a lot.
(If this comment was disrespectful, please report it.)

 
12/13/2002 2:37:32 PM

Well documented and good example of optimum use of classes.
Well done! Thanks.
(If this comment was disrespectful, please report it.)

 
1/18/2003 3:21:49 PMDrDave

Nice Code... I downloaded it a while back (first version) and learned alot from it ;}

But I have a quick question... I have a fairly large database that im loading (over 2000 sections, 27000 files) and I cant load the whole db at once cause it takes to long.. so I was woundering if you could help me out on the BeforExpand event.....

Thanks in advance

PeAcE
DrDave
(If this comment was disrespectful, please report it.)

 
1/20/2003 3:36:36 AMXTab

Nice, well commented, easy to follow example - Five well deserved Globes from me !
(If this comment was disrespectful, please report it.)

 
4/20/2003 10:49:32 PMEJ T

Sweet! Iv been looking for code like this from all over the internet for the past week. This is greate work, not just with the treeview control, but will all of the codeing. You are a credit to the human race.
Now if it only supported XML ....

Nice,
EJ T
(If this comment was disrespectful, please report it.)

 
5/3/2003 1:45:53 PMFriendlyFiend

Cool code....now if only XML could be shoe horned in *hint* *hint* ;)
(If this comment was disrespectful, please report it.)

 
6/6/2003 6:10:53 AM

Excellent code. Easy to understand and provides full features.


(If this comment was disrespectful, please report it.)

 
6/12/2003 6:12:29 AMRuss Green

Mark

I've been looking at your TreeView Template. Great code! I've been learning to program myself and this is by far the most complex thing I've come across so far.

I'm implementing your treeview code in a personal project of my own. I'm at the point now where I'm trying to populate other controls with data from the database based on what Tree Node is selected. I'm interested to learn how you would approach it. I've tried the following but I'm getting errors. http://www.russgreen.net/software/misc/code.txt

I get the error "No value given for one or more required parameters". I have stepped through the debugger to the point where the exception is caught (the error occurs within the GetReader function) and taken a screenshot http://www.russgreen.net/software/misc/SCD_debugging.gif

I would be so grateful if you could point out what I've missed here.

Many thanks

Russ
(If this comment was disrespectful, please report it.)

 
6/19/2003 10:17:48 PM

This is a great code! I am now starting to study VB.NET. Thank you for sharing your talent in planet source code! :)

(If this comment was disrespectful, please report it.)

 
7/3/2003 9:36:15 AM

I don't think that's the best way to use TREEVIEW. Change the IsRoot value in TreeViewEx.mdb, you guys will get some problems
(If this comment was disrespectful, please report it.)

 
11/4/2003 4:27:44 PM

Amazing example!!Well documented...
except I have a question ..what is the iSort field used for...i am confused escp with this comment
(If this comment was disrespectful, please report it.)

 
11/4/2003 4:28:24 PM

Amazing example!!Well
documented...
except I have a question
..what is the iSort field used for...i
am confused escp with this comment
in the code
/ Save all records to the database, starting with the root node. We
'// maintain the sort order so that the nodes can be restored in the
'// order that they were read. This will prevent adding a node before
'// adding its parent.
(If this comment was disrespectful, please report it.)

 
2/1/2004 5:17:36 PM

I am expecting a C# version of this, could anybody help me?

Author: Thanks for sharing your code with us!
(If this comment was disrespectful, please report it.)

 
2/1/2004 5:18:23 PM

I am expecting a C# version of this, could anybody help me?

Author: Thanks for sharing your code with us!


(If this comment was disrespectful, please report it.)

 
6/8/2004 12:22:55 PM

Well i am downloading the code but i guess that looking at what most of the users are saying it's worth checking out so i would appreciate it if the author would just email me a line so that i can have his email address to contact him because i know that i would definitely have some questions.
THANKS
(If this comment was disrespectful, please report it.)

 
6/8/2004 12:28:18 PMMark E. Thorogood

Hi everyone,

My e-mail address is thorogoo@nova.edu if you need to contact me regarding the above.
(If this comment was disrespectful, please report it.)

 
7/15/2004 5:54:17 AM

goooda!!!! :)
(If this comment was disrespectful, please report it.)

 
3/9/2005 10:16:55 AM

Finally, an example of TreeView that saves the data back to a database!! I have looked in dozens of books and spent hours searching the Internet for an example like this. Thank You !!! My only critcism is the global g_bOK variable makes me nervous. I'd feel better if that was a more localized variable.
(If this comment was disrespectful, please report it.)

 
6/8/2005 8:55:27 AM

I found exactly what I wanted in this
program such as how to save a tree
structure into a database and how to
drag and drop nodes in a treeview.
Thanks a lot.
(If this comment was disrespectful, please report it.)

 
11/13/2006 4:24:43 AMPangke

Thanks....program...
(If this comment was disrespectful, please report it.)

 
3/6/2007 2:58:44 AMsayi

could i obtain this code using sql database
(If this comment was disrespectful, please report it.)

 
1/19/2008 5:37:53 AMSteven Atkiss

Hi Mark, I am ridiculously new to .NET. Started last night after years of VB 6 so I don't know how to do simple debugging yet. When I run the app it says "Unable to run app because of incorrect configuration"? I am using the express version. I know it's not your program at fault just something I need to do I presume.

Can you help?
Kind Regards.
(If this comment was disrespectful, please report it.)

 
5/3/2008 5:49:48 AMJohn Attfield

Excellent. Every thing you need for a treeview controlled database. Converts to VB.2005 with no problems.

Thanks
(If this comment was disrespectful, please report it.)

 
6/23/2009 10:27:08 AMBrick

To get code to run in VS2008:
change the first line in the two .config files in the bin directory to:

(If this comment was disrespectful, please report it.)

 
11/25/2009 4:45:20 AMPeter

I encounter this problem. Please help

rdr = CDataSvcs.GetReader("SELECT * FROM [TreeViewItems] ORDER By iSort;")

Object reference not set to an instance of an object. For this statement
(If this comment was disrespectful, please report it.)

 
2/17/2010 1:32:25 AMZain

Please tell me how to get the ID (Primary Key) of the selected Node.

I can get the Text and Full Path but can't figure out how to get the ID..

Please help.
(If this comment was disrespectful, please report it.)

 
11/15/2011 3:41:25 PMWilly

Ok, very nice!
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.