Export (0) Print
Expand All
Expand Minimize

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 2005. 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 2005, 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 2005, 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 2005.

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 Basic 2005
Private Sub TreeView1_AfterSelect(ByVal sender As Object, ByVal e As _
System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect

    TreeView1.SelectedNode.Expand()
End Sub

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 Basic 2005
Dim 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 2005 equivalents. Those properties, methods, and events that have the same name and behavior are not listed. All Visual Basic 2005 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 2005, links are provided to topics that present alternatives.

Properties

Visual Basic 6.0 Visual Basic 2005 Equivalent

Appearance

New implementation. For more information, see Appearance and BorderStyle Properties for Visual Basic 6.0 Users.

BackColor

BackColor

NoteNote

Colors are handled differently in Visual Basic 2005. For more information, see Color Behavior for Visual Basic 6.0 Users.

Container

Parent

DragIcon

DragMode

New implementation. For more information, see Drag and Drop for Visual Basic 6.0 Users.

Font Font

FontBold

FontItalic

FontName

FontSize

FontStrikethrough

FontUnderline

Font

NoteNote

Fonts are handled differently in Visual Basic 2005. For more information, see Font Object for Visual Basic 6.0 Users.

Height

Height, Size

NoteNote

Coordinates are handled differently in Visual Basic 2005. 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

Handle

Indentation

Indent

Index

New implementation. For more information, see Control Arrays for Visual Basic 6.0 Users.

Left

Left

NoteNote

Coordinates are handled differently in Visual Basic 2005. For more information, see Coordinate System for Visual Basic 6.0 Users.

LineStyle

ShowRootLines

MouseIcon

New implementation. For more information, see Cannot set a custom MousePointer.

MousePointer

Cursor

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

Scrollable

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

Top

NoteNote

Coordinates are handled differently in Visual Basic 2005. 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

Width, Size

NoteNote

Coordinates are handled differently in Visual Basic 2005. For more information, see Coordinate System for Visual Basic 6.0 Users.

Methods

Name Visual Basic 2005 Equivalent

Drag

New implementation. For more information, see Drag and Drop for Visual Basic 6.0 Users.

GetVisibleCount

VisibleCount property.

HitTest

GetNodeAt, GetNodeAt

Move

SetBounds

NoteNote

Coordinates are handled differently in Visual Basic 2005. 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

Focus

ShowWhatsThis

New implementation. For more information, see Help Support for Visual Basic 6.0 Users.

StartLabelEdit

BeginEdit

ZOrder

BringToFront or SendToBack method

Events

Visual Basic 6.0 Visual Basic 2005 Equivalent

Collapse

BeforeCollapse

DblClick

DoubleClick

DragDrop

DragOver

New implementation. For more information, see Drag and Drop for Visual Basic 6.0 Users.

Expand

AfterExpand

GotFocus

Enter

LostFocus

Leave

NodeCheck

AfterCheck

NodeClick

NodeMouseClick

OLECompleteDrag

OLEDragDrop

OLEDragOver

OLEGiveFeedback

OLESetData

OLEStartDrag

New implementation. For more information, see Drag and Drop for Visual Basic 6.0 Users.

Validate

Validating

Upgrade Notes

When a Visual Basic 6.0 project is upgraded to Visual Basic 2005, 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

Community Additions

ADD
Show:
© 2014 Microsoft