JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Handling Tree View Events

Tree views have quite a number of events; see Table 10.5 for the list. The default event is the AfterSelect event, which occurs after a node has been selected. This event is an event of the tree view control, not of the TreeNode object that was selected, but you can determine which node was selected with the TreeViewEvent Args object that is passed to you, because it has a Node property that holds the selected node. For example, here's how I display the text of a selected node in a text box:

Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, _
    ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles _
    TreeView1.AfterSelect
    TextBox1.Text = "You clicked: " & e.Node.Text
End Sub

You can see how this works in Figure 10.11, in the TreeViews example on the CD-ROM, where I've clicked a node, and the program is reporting which one I clicked. To check if the selected node is a particular node in the tree, you can use code, like this: If e.Node Is TreeView1.Nodes(233) Then.


Figure 10.11: Handling tree view events.
Previous Section Next Section




JavaScript Editor Free JavaScript Editor     JavaScript Editor