This section describes the differences between VB6 and .NET controls and the problems
you can find in migrating VB6 applications with user-interface. The differences
that are common to most controls are described in the
For a list of differences between VB6 and VB.NET language, see
The AddItem method isn’t supported and can be rendered using the Add or Insert methods of the Items collection, depending on whether the method receives an index argument.
The Clear method isn’t supported under VB.NET; you can use the Items.Clear method instead.
The Click event in the VB.NET control doesn’t fire when a new element is selected via code or by using the keyboard. The actual .NET counterpart of this event is the SelectedIndexChanged event.
The Columns property isn’t supported. You can approximate its effect by opportunely assigning the MultiColumn and ColumnWidth properties, which requires that you correctly calculate the width of each column.
VB Migration Partner fully supports this property.
The DblClick event maps to the DoubleClick event. However, you should also take into account that under VB6 no event fires if the mouse isn’t clicked on an element.
VB Migration Partner fully supports the DblClick event; as in VB6 no event fires if the mouse isn’t clicked on an element.
The ItemCheck event is supported but has a different syntax. Moreover, under VB6 this event fires when the checked state has been already assigned, whereas in VB.NET it fires before the assignment occurs. The code inside a VB6 event handler can reset the checked state of an element by simply assigning it, whereas code in a VB.NET event handler must assign the new state to the NewValue property of the ItemCheckEventArgs object passed as an argument to the event handler.
VB Migration Partner fully supports this event and automatically accounts for all the behavioral differences between VB6 and VB.NET.
The ItemData property isn’t supported by the VB.NET ListBox control. Code migrated by the Upgrade Wizard uses helper methods to render this property.
Interestingly, the items of a .NET ListBox control can be objects of any type, not just strings. If an object is used, the ListBox control displays whatever the object’s ToString method returns. If you need to associate data with an item, you can just create a class that contains two items, as in this example:
Public ItemText As String
Public ItemData As Object
Public Overrides Function ToString() As String
VB Migration Partner fully supports this property; migrated code works correctly even if the control is accessed in late-bound mode.
The List property isn’t supported; it can be rendered using the Items collection. Notice that the VB6 List property returns an empty string when the index is out of valid range, whereas you get an exception if you attempt to access a nonexisting element of the .NET Items collection. Along the same line, in VB6 you can create a new element by assigning the List property of the first available index:
List1.List(List1.ListCount) = "new item"
This feature isn’t supported by the Items collection.
VB Migration Partner fully support this property, including all its quirks and undocumented behaviors.
The ListCount property isn’t supported under VB.NET; you can use the Items.Count property instead.
The ListIndex property isn’t supported under VB.NET; you can use the SelectedIndex property instead.
The MultiSelect property isn’t supported and must be translated using the SelectionMode property.
The NewIndex property isn’t supported; it broadly corresponds to the value returned by the Add method of the Items collection.
VB Migration Partner fully support this property, so that migrated code is guaranteed to work as intended.
The RemoveItem method isn’t supported and can be rendered using the RemoveAt method of the Items collection. There are other differences in behavior to take into account, though. For example, under VB6 the ListIndex property points to the element prior to the one being removed if the ListBox supports multiple selections, whereas in VB.NET the ListIndex property is always set to -1.
VB Migration Partner support this method and perfectly replicates all its quirks, thus no adjustments are necessary after the migration.
The Scroll event isn’t supported under .NET and it can’t easily simulated. For example, you can approximate it by hooking the SelectedIndexChanged event, but you wouldn’t trap the cases when the user scrolls the listbox contents without changing the current element. The only reliable way to get a notification when the ListBox control is scrolled is by means of Windows subclassing.
VB Migration Partner fully supports this event.
The SelCount readonly property isn’t supported; it can be rendered by means of the SelectedItems.Count property.
The Selected property isn’t supported; it can be rendered by means of the GetSelected method for simple ListBox controls, or the GetItemChecked and SetItemChecked methods for ListBox controls with checkboxes.
The VB.NET ListBox control doesn’t support the Style property. ListBox controls with the Style property set to 1-vbListBoxCheckbox must be migrated to the CheckedListBox control instead of the ListBox control.
Both the Upgrade Wizard and VB Migration Partner migrate a ListBox with Style=1 to the most appropriate .NET control.