VB Migration Partner

KNOWLEDGE BASE - Forms and controls


Previous | Index | Next 

[PRB] Removing an item from a multi-selectable ListBox resets ListIndex property

Here’s an undocumented behavior of the VB6 ListBox control: if you remove the currently selected item with the RemoveItem method, the value that the ListIndex property assumes after the removal depends on the MultiSelect property:

  • if MultiSelect is equal to 0-None, then the ListIndex property is assigned the value -1 and no item appears to be selected in the listbox;
  • if the MultiSelect property is set to 1-Simple or 2-Extended, then the ListIndex property is assigned a value one minus the index of the element that was removed.

The following code snippet shows this feature:

        ' lstSimple has MultiSelect=0-None, lstMulti has MultiSelect=2-Extended
        lstSimple.ListIndex = 10
        lstSimple.RemoveItem 10
        Debug.Print lstSimple.ListIndex     ' displays -1
        lstMulti.ListIndex = 10
        lstMulti.RemoveItem 10
        Debug.Print lstMulti.ListIndex      ' displays 9

All .NET listbox controls – including the VB6ListBox and VB6WLList controls – behave in a more predictable way: if you remove the item that is currently selected then the ListIndex property (and the SelectedIndex property) are set equal to -1, regardless of whether the listbox control supports multiple selections.

In most cases this detail has no impact on how a migrated VB.NET application behaves. If it does, however, you may want to manually set the value of the ListIndex property after all calls to the Remove method:

        lstMulti.ListIndex = 10
        lstMulti.RemoveItem 10
        lstMulti.ListIndex = 9
Previous | Index | Next 




Follow Francesco Balena on VB6 migration’s group on

LinkedIn





Read Microsoft Corp’s official case study of a VB6 conversion using VB Migration Partner.




Code Architects and its partners offers remote and onsite migration services.

More details




Subscribe to our free newsletter for useful VB6 migration tips and techniques.

newsletter



To learn more about your VB6 applications, run VB6 Analyzer on your source code and send us the generated text file. You will receive a detailed report about your VB6 applications and how VB Migration Partner can help you to quickly and effectively migrate it to .NET.

Get free advice



A fully-working, time-limited Trial Edition of VB Migration Partner allows you to test it against your actual code

Get the Trial




The price of VB Migration Partner depends on the size of the VB6 application, the type of license, and other factors

Request a quote




Migrating a VB6 application in 10 easy steps

Comparing VB Migration Partner with Upgrade Wizard

Migration tools: Feature Comparison Table

All whitepapers