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 Controls (general) section.

For a list of differences between VB6 and VB.NET language, see here.

Unless otherwise stated, VB Migration Partner fully supports all the Visual Basic 6 features mentioned in this page. It is worth noticing that names of properties and methods are preserved, which ensures that those even late-bound references work correctly after the migration to VB.NET. For more information, please read the manual and the knowledge base section.





ComboBox control

AddItem method

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.



Change event

The Change event maps to the TextChanged event, but in the case of the ComboBox controls there are several differences between VB6 and VB.NET. The VB6 Change event fires only when the text in the edit area is modified, whereas the VB.NET TextChanged event also fires when a different item is selected in the list area, when the AddItem is called, or when the value of the current element is assigned programmatically via the List property.

For this reason, the TextChanged event handler generated by the Upgrade Wizard may fire at the wrong time and cause bogus results or runtime errors. This never happens with VB Migration Partner, which perfectly mimics the VB6 behavior.



Clear method

The Clear method isn’t supported under VB.NET; you can use the Items.Clear method instead.



Click event

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.



ItemData property

The ItemData property isn’t supported by the VB.NET ComboBox control. Code migrated by the Upgrade Wizard uses helper methods to render this property.

Interestingly, the items of a .NET ComboBox control can be objects of any type, not just strings. If an object is used, the ComboBox 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:

        Class ListBoxItem
            Public ItemText As String   ' what is displayed
            Public ItemData As Object   ' associated data

            Public Overrides Function ToString() As String
                Return ItemText
            End Function
        End Class

VB Migration Partner fully supports this property; migrated code works correctly even if the control is accessed in late-bound mode.



List property

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.



ListCount property

The ListCount property isn’t supported under VB.NET; you can use the Items.Count property instead.



ListIndex property

The ListIndex property isn’t supported under VB.NET; you can use the SelectedIndex property instead.



Locked property

Under VB6 the Locked property allows you to create a ComboBox with an edit area whose contents can’t be modified. This feature can’t be easily replicated under VB.NET and can only be approximated by creating a ComboBox control with DropDownList style.

VB Migration Partner supports the Locked property using the technique just described.



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



RemoveItem method

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



Scroll event

The Scroll event isn’t supported under .NET and it can only be approximated by trapping the SelectedIndexChanged event and by subclassing the window that is created when the dropdown list appears.

VB Migration Partner fully supports this event.



SelStart, SelLength, and SetText properties

The VB6’s SetStart, SelLength, and SetText properties have been renamed as SelectionStart, SelectionLength, and SelectionText under VB.NET, respectively.

VB  Migration Partner fully supports the SelStart, SelLength, and SelText properties, so that migrated code works as intended even if the control is accessed in late-bound mode.



SetFocus method

The VB6 SetFocus method maps to the VB.NET Focus method. In addition, when used on a ComboBox control, the SetFocus method selects the entire contents of the edit area.



Text property

There are a few minor differences in how VB6 and VB.NET handle the Text property. Under VB6, assigning the Text property raises a runtime error if the control is a dropdown list and you attempt to assign a value different from the value of the current element. No error ever occurs in VB.NET.

VB Migration Partner perfectly mimics the VB6 behavior.



TopIndex property

The VB.NET ComboBox control doesn’t support the TopIndex property. You can read and modify the index of the topmost element by sending a CB_GETTOPINDEX and CB_SETTOPINDEX message to the control using the DefWndProc protected method.

VB Migration Partner fully supports this property. No manual edits of the migrated code are needed.