TreeView Control for Visual Basic 6.0 Users
The TreeView control in Visual Basic 6.0 is replaced by the TreeView control in Visual Basic 2008. The names of some properties, methods, events, and constants are different, and in some cases there are differences in behavior.
Conceptual Differences
SingleSel Property
In Visual Basic 6.0, the SingleSel property of a TreeView control determines whether a node expands to show its child nodes when selected. Setting this property to True causes the node to expand when selected and causes the previously selected node to contract.
In Visual Basic 2008, the SingleSel property no longer exists. By default, a node does not expand when clicked (the default is equivalent to setting the SingleSel property to False in Visual Basic 6.0). You can use the AfterSelect event to determine when a node has been selected, and then use the Expand or Collapse method to control the expansion behavior.
Image and SelectedImage Properties
In Visual Basic 6.0, it is possible to assign a SelectedImage property to a TreeView control node without assigning an Image property.
In Visual Basic 2008, the TreeNode object of a TreeView control cannot have a SelectedImage property unless it also has an Image property. If you need to emulate Visual Basic 6.0 behavior, you can assign an empty image to the Image property.
Other Differences
In addition, there are numerous conceptual differences that apply to all controls, including differences in data binding, font handling, drag-and-drop operations, Help support, and more. For more information, see Windows Forms Concepts for Visual Basic 6.0 Users.
Code Changes for the TreeView Control
The following examples illustrate differences in coding techniques between Visual Basic 6.0 and Visual Basic 2008.
Code Changes for Expanding a Selected Node in a TreeView Control
The following code demonstrates how to expand a TreeView node when a user selects it.
' Visual Basic 6.0
TreeView1.SingleSel = True
' Visual BasicPrivateSub TreeView1_AfterSelect(ByVal sender AsObject, ByVal e As _
System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
TreeView1.SelectedNode.Expand()
EndSub
Code Changes for Adding Nodes in a TreeView Control
The following code demonstrates how to add a new node as a child of the currently selected node.
' Visual Basic 6.0
Dim nodX As Node
Set nodX = TreeView1.Nodes.Add(Node, tvwChild, , "New Node")
' Visual BasicDim nodX As TreeNode = New TreeNode("New Node")
TreeView1.SelectedNode.Nodes.Add(nodX)
TreeView Control Property, Method, and Event Equivalencies
The following tables list Visual Basic 6.0 properties, methods, and events, along with their Visual Basic 2008 equivalents. Those properties, methods, and events that have the same name and behavior are not listed. All Visual Basic 2008 enumerations map to the System.Windows.Forms namespace unless otherwise noted.
This table provides links to topics explaining behavior differences. Where there is no direct equivalent in Visual Basic 2008, links are provided to topics that present alternatives.
Properties
Visual Basic 6.0 |
Visual Basic 2008 Equivalent |
---|---|
Appearance |
New implementation. For more information, see Appearance and BorderStyle Properties for Visual Basic 6.0 Users. |
BackColor |
Note:
Colors are handled differently in Visual Basic 2008. For more information, see Color Behavior for Visual Basic 6.0 Users.
|
Container |
|
DragIcon DragMode |
New implementation. For more information, see Drag and Drop for Visual Basic 6.0 Users. |
FontFont FontBold FontItalic FontName FontSize FontStrikethrough FontUnderline |
Note:
Fonts are handled differently in Visual Basic 2008. For more information, see Font Object for Visual Basic 6.0 Users.
|
Height |
Note:
Coordinates are handled differently in Visual Basic 2008. For more information, see Coordinate System for Visual Basic 6.0 Users.
|
HelpContextID |
New implementation. For more information, see Help Support for Visual Basic 6.0 Users. |
HWnd |
|
Indentation |
|
Index |
New implementation. For more information, see Control Arrays for Visual Basic 6.0 Users. |
Left |
Note:
Coordinates are handled differently in Visual Basic 2008. For more information, see Coordinate System for Visual Basic 6.0 Users.
|
LineStyle |
|
MouseIcon |
New implementation. For more information, see Cannot set a custom MousePointer. |
MousePointer |
For a list of constants, see MousePointer for Visual Basic 6.0 Users. |
OLEDragMode OLEDropMode |
New implementation. For more information, see Drag and Drop for Visual Basic 6.0 Users. |
Parent |
FindForm method |
Scroll |
|
SingleSel |
New implementation. Use the NodeMouseClick event. |
Style |
New implementation property. 0 or Standard maps to the CheckedListBox control, 1 or Checkbox maps to the CheckedListBox control. |
ToolTipText |
ToolTip component For more information, see ToolTip Support for Visual Basic 6.0 Users. |
Top |
Note:
Coordinates are handled differently in Visual Basic 2008. For more information, see Coordinate System for Visual Basic 6.0 Users.
|
WhatsThisHelpID |
New implementation. For more information, see Help Support for Visual Basic 6.0 Users. |
Width |
Note:
Coordinates are handled differently in Visual Basic 2008. For more information, see Coordinate System for Visual Basic 6.0 Users.
|
Methods
Name |
Visual Basic 2008 Equivalent |
---|---|
Drag |
New implementation. For more information, see Drag and Drop for Visual Basic 6.0 Users. |
GetVisibleCount |
VisibleCount property. |
HitTest |
|
Move |
Note:
Coordinates are handled differently in Visual Basic 2008. For more information, see Coordinate System for Visual Basic 6.0 Users.
|
OLEDrag |
New implementation. For more information, see Drag and Drop for Visual Basic 6.0 Users. |
SetFocus |
|
ShowWhatsThis |
New implementation. For more information, see Help Support for Visual Basic 6.0 Users. |
StartLabelEdit |
|
ZOrder |
BringToFront or SendToBack method |
Events
Visual Basic 6.0 |
Visual Basic 2008 Equivalent |
---|---|
Collapse |
|
DblClick |
|
DragDrop DragOver |
New implementation. For more information, see Drag and Drop for Visual Basic 6.0 Users. |
Expand |
|
GotFocus |
|
LostFocus |
|
NodeCheck |
|
NodeClick |
|
OLECompleteDrag OLEDragDrop OLEDragOver OLEGiveFeedback OLESetData OLEStartDrag |
New implementation. For more information, see Drag and Drop for Visual Basic 6.0 Users. |
Validate |
Upgrade Notes
When a Visual Basic 6.0 project is upgraded to Visual Basic 2008, any TreeView controls are upgraded to Windows Forms TreeView controls. Where properties, methods, and events have no equivalent or have differences in behavior, upgrade notes or warnings are added to your code.
See Also
Tasks
How to: Add Custom Information to a TreeView or ListView Control (Windows Forms)
How to: Iterate Through All Nodes of a Windows Forms TreeView Control