ListView Control for Visual Basic 6.0 Users

The ListView control in Visual Basic 6.0 is replaced by the ListView 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

DropHighlight Property

In Visual Basic 6.0, when the cursor moves over a ListItem object in a ListView control, the DropHighlight property is used to highlight the ListItem object with the system highlight color . This property is commonly used in drag-and-drop operations.

In Visual Basic 2008, the DropHighlight property no longer exists; you can achieve the same effect by ownerdrawing (also known as custom drawing) the highlight in the MouseEnter and MouseLeave events. For more information, see Controls with Built-In Owner-Drawing Support.

FlatScrollBar Property

In Visual Basic 6.0, the FlatScrollBar property determines whether the scroll bar in a ListView control has a flat (two-dimensional) appearance.

In Visual Basic 2008, the FlatScrollBar property no longer exists; scroll bars in the ListView control always have a three-dimensional appearance.

HideColumnHeaders Property

In Visual Basic 6.0, the HideColumnHeaders property determines whether ColumnHeader objects in a ListView control are hidden in Report view.

In Visual Basic 2008, the HideColumnHeaders property no longer exists; you can control the visibility of the column headers by setting the HeaderStyle property.

ItemClick Event

The Visual Basic 6.0 ListView control has both a Click and an ItemClick event. The ItemClick event takes a ListItem object as an argument.

In Visual Basic 2008, there is no longer an ItemClick event. Instead you can use the Click event and the EventSender.FocusedItem argument to determine which ListViewItem was clicked.

Sorting

In Visual Basic 6.0, sorting of a ListView control is accomplished using a combination of the Sorted, SortKey, and SortOrder properties. Sorted determines whether sorting is enabled, SortOrder determines if sorting is ascending or descending, and SortKey specifies a sub-item to be used for sorting instead of the text.

In Visual Basic 2008, sorting is accomplished using the Sorting property, which enables sorting and sets the sort order in a single step. The SortKey property is replaced by the ListViewItemSorter property.

View Property

In Visual Basic 6.0, the View property determines how items in a ListView control are displayed—as large icons with text (lvwIcon), as small icons with text (lvwSmallIcon), as a list (lvwList), or as a list with sub-items (lvwReport).

In Visual Basic 2008, the View property still exists, but the enumerations are different. lvwIcon is replaced by LargeIcon, lvwSmallIcon by SmallIcon, lvwList by List, and lvwReport by Details. In addition, there is a new view, Tile, where each item appears as a full-sized icon with the item label and sub-item information to the right of it.

Code Changes for the ListView Control

The following examples illustrate differences in coding techniques between Visual Basic 6.0 and Visual Basic 2008.

Code Changes for Determining the Selected Item in a ListView Control

The following code example assigns the selected ListView item to a variable.

' Visual Basic 6.0
Dim theItem As ListItem
theItem = ListView1.SelectedItem
' Visual BasicDim theItem As ListViewItem
If ListView1.SelectedItems.Count > 0 Then
    theItem = ListView1.SelectedItems(0)
Else
    theItem = NothingEndIf

Code Changes for Determining All Selected Items in a ListView Control

The following code example displays a message box with the text of each selected item in a ListView control.

' Visual Basic 6.0
For i = 1 To ListView1.ListItems.Count
    If ListView1.ListItems(i).Selected = True Then
        MsgBox(ListView1.SelectedItem
    End If
Next i
' Visual BasicForEach selectedItem As ListViewItem In ListView1.SelectedItems
    MsgBox(selectedItem.Text)
Next

ListView 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.

Arrange

Alignment

BackColor

BackColor

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

ColumnHeaderIcons

ImageIndex, ImageKey

ColumnsHeaders

Columns

Container

Parent

DragIcon

DragMode

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

DropHighlight

New implementation.

FlatScrollBar

New implementation.

FontFont

FontBold

FontItalic

FontName

FontSize

FontStrikethrough

FontUnderline

Font

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

Height

Height, Size

NoteNote:
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

Handle

Icons

LargeImageList

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 2008. For more information, see Coordinate System for Visual Basic 6.0 Users.

ListItems

Items

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

Picture

BackgroundImage

PictureAlignment

BackgroundImageTiled

SelectedItem

SelectedItems

SmallIcons

SmallImageList

Sorted

SortOrder

Sorting

SortKey

ListViewItemSorter

TextBackground

BackColor

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 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

Width, Size

NoteNote:
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.

FindItem

FindItemWithText

GetFirstVisible

TopItem

Move

SetBounds

NoteNote:
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.

Refresh

RedrawItems

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 2008 Equivalent

DblClick

DoubleClick

DragDrop

DragOver

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

GotFocus

Enter

ItemClick

No direct equivalent.

LostFocus

Leave

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 2008, any ListView controls are upgraded to Windows Forms ListView 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

Other Resources

ListView Control (Windows Forms)