Inserting elements in a ListView
In this section, you can see how to change the getAdd() stub with code that let you insert a bulk of elements into a ListView.
Description
Certain code patterns in VB6 to insert a massive amount of elements in a ListView may present a performance gap in .NET when the code is converted. This entry covers that situation and how it can be fixed manually.
Inserting elements
In VB6 it is common to find a loop, like a do-while, iterating over a list of elements and inserting them into a ListView. Let's consider the following example:
When converted, that code will look like:
Besides the manual change to overcome the getAdd() stub, that can be replaced by something like:
However, inserting one ListViewItem at a time can take a lot of time in .NET. Instead of this way of adding elements, consider inserting a bulk of elements at once:
The above while-loop insert elements into a typed List of ListViewItem and then, after the while, the ListView.AddRange() method is used to insert the bulk of items.
Last updated