TreeView Sample Applications

 

The following sample applications are included when you purchase the VB 2010 Tutorial Download Package or the VB 2010 "Extra" Sample Applications from The VB Programmer.

 

1. Basic TreeView Database Demo 1

This is a sample program that shows how data from related tables in a database would typically be displayed in a TreeView control. Salesmen are displayed in the high-level nodes of the tree. When a salesman node is expanded, the companies that the salesman is responsible for are displayed at the next level of the tree. When a company is clicked, data for the contacts associated with that company are displayed in the ListView in the lower portion of the screen. In this sample application, all of the data for the TreeView (the salesmen and their associated companies) is loaded at the same time (this in contrast to the technique used for loading the TreeView in the second demo, described below).

 

 

 

2. Basic TreeView Database Demo 2

This sample program behaves identically to the first demo, described above. The difference from a programming perspective is in the way that the TreeView is loaded. Here, only the salesmen nodes are loaded initially (each with a "dummy" child node below it so that the "+" appears on the left of the node). When a salesman node is expanded, a query is run to get the companies associated with that salesman (the company data is displayed as children nodes below the salesman node, and  the "dummy" node is deleted). This "dynamic" loading technique is practical when dealing with large amounts of data, where it would take too long to fully load the tree all at once.

 

 

 

3. TreeView Drag-and-Drop (with Scrolling)

This sample application shows how to perform drag and drop (with scrolling) within a TreeView. The sample program shows salesmen with companies they are responsible for calling upon. A user (such as the sales manager) can re-assign a company to a different salesman by dragging the company node below one salesman and dropping it on another salesman. The changes that the user makes are saved back to the database.