Hello,
I have a bunch of strings and a ready listview but my problem is to insert those strings into the list view in column 2, while running.
I can't find any solution, I have only found tutorials on creating a list view and sub items via code, but i need to change the column while running.
Thanks.

You can search through the items in a ListView, by iterating through the "Items" collection. Further, each item has a SubItems collection. So, with code like this, you can look for an item in a ListView and do something with it. In this case, I have a ListView called "lvBatters" and I am try to locate a batter (value in txtBatter) and replace the item in column 2 of the ListView with the batting average (stored in sAvg - converted to a string earlier):

bool bFound = false;
    foreach (ListViewItem item in lvBatters.Items)
    {
        if (item.Text == txtBatter.Text)
        {
            item.SubItems[1].Text = sAvg;  // Set the batting average
            bFound = true;
            break;   // break out of the loop
        }
    }

    // If I don't find the batter in the list, add it!
    if (!bFound)
    {
        ListViewItem i = new ListViewItem(txtBatter.Text);
        i.SubItems.Add(sAvg);
        lvBatters.Items.Add(i);
    }

Keep in mind, "items.SubItems[0].Text" is the value in the first column!

Try that, and see what happens.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.