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.
Last updated
private void Form_Load()
{
string[] ss = new string[]{"", "", "", "", "", "", ""};
ss[1] = "this";
ss[2] = "is";
ss[3] = "a";
ss[4] = "sample";
ss[5] = "of";
ss[6] = "code";
ListViewItem lv = null;
int k = 1;
while(k < 7)
{
//UPGRADE_ISSUE: (2064) MSComctlLib.IListItems method ListView1.ListItems.Add was not upgraded.
lv = this.ListView1.Items.getAdd();
lv.Text = ss[k];
k++;
};
}lv = new ListViewItem();
listView1.Items.Add(lv);private void Form_Load()
{
string[] ss = new string[]{"", "", "", "", "", "", ""};
ss[1] = "this";
ss[2] = "is";
ss[3] = "a";
ss[4] = "sample";
ss[5] = "of";
ss[6] = "code";
List<ListViewItem> items = new List<ListViewItem>();
ListViewItem lv = new ListViewItem();
int k = 1;
while(k < 7)
{
lv = new ListViewItem();
items.Add(lv);
lv.Text = ss[k];
k++;
};
listView1.Items.AddRange(items.ToArray());
}