Presentation is loading. Please wait.

Presentation is loading. Please wait.

TreeView Control.

Similar presentations


Presentation on theme: "TreeView Control."— Presentation transcript:

1 TreeView Control

2 TreeView Control Drill Down interface
Displays information in a hierarchical manner. Nodes collection: Root: No parent Other nodes have a single parent. Siblings: Children have the same parent. First Sibling, Last Sibling TreeNode Editor

3 TreeView Properties TopNode Nodes GetNodeCount(False) SelectedNode
Nodes(Index) GetNodeCount(False) SelectedNode FullPath

4 Display Root Node’s Children
Dim TrNode As TreeNode For Each TrNode In TreeView1.TopNode.Nodes MessageBox.Show(TrNode.Text) MessageBox.Show(TrNode.FullPath) Nextree Note: Nodes is a collection of children nodes directly belong to a parent node.

5 Displaying Selected Node’s Information
Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect MessageBox.Show(TreeView1.SelectedNode.Text) MessageBox.Show(TreeView1.SelectedNode.FullPath()) End Sub

6 Adding a TreeNode Programmatically
Nodes collection’s Add method: Add(string) TreeView1.Nodes.Add("Root") Add(a tree node) Define a tree node object Dim myNode As New TreeNode() myNode.Text = "Root" TreeView1.Nodes.Add(myNode)

7 TreeView1.Nodes.Add("Root")
TreeView1.Nodes(0).Nodes.Add("Child1") TreeView1.Nodes(0).Nodes.Add("Child2") TreeView1.Nodes(0).Nodes.Add("child3") TreeView1.Nodes(0).Nodes(0).Nodes.Add("GrandC11") TreeView1.Nodes(0).Nodes(0).Nodes.Add("GrandC12") TreeView1.Nodes(0).Nodes(1).Nodes.Add("GrandC21") TreeView1.Nodes(0).Nodes(2).Nodes.Add("GrandC31") TreeView1.Nodes(0).Nodes(2).Nodes.Add("GrandC32") TreeView1.Nodes(0).Nodes(2).Nodes(0).Nodes.Add("GGrandC311")

8 Recursive Procedure A procedure that calls itself.

9 Creating a TreeView of Directories
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim DiskDrive As String = "C:\" TreeView1.Nodes.Add(DiskDrive) Call GetFolders(TreeView1.Nodes(0)) End Sub Private Sub GetFolders(ByVal CurrentFolder As TreeNode) Dim FolderPath As String FolderPath = CurrentFolder.Text Dim folder As String If Directory.GetDirectories(FolderPath).Length <> 0 Then For Each folder In Directory.GetDirectories(FolderPath) Dim newNode As New TreeNode(folder) CurrentFolder.Nodes.Add(newNode) Call GetFolders(newNode) Next End If

10 Displaying Files in Selected Folder
Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect Dim currDir As String currDir = TreeView1.SelectedNode.Text Dim fName As String ListBox1.Items.Clear() For Each fName In Directory.GetFiles(currDir) ListBox1.Items.Add(fName) Next End Sub


Download ppt "TreeView Control."

Similar presentations


Ads by Google