Okay, how do I programmatically add items from an List<ListViewItem.ListViewSubItem> to an ListView? I am trying to load 3 lists of items next to each other, but it doesn’t seem to work…
Here’s some code I have right now:
//----------PluginHandler.cs----------/
public static List<ListViewItem> PluginList = new List<ListViewItem>();
public static List<ListViewItem.ListViewSubItem> PluginList2 = new List<ListViewItem.ListViewSubItem>();
PluginList.Clear();
PluginList2.Clear();
foreach (var item in plugin.versions)
{
var lvitem = new ListViewItem { Text = item.name };
var lvitem2 = new ListViewItem.ListViewSubItem { Text = item.filename };
PluginList.Add(lvitem);
PluginList2.Add(lvitem2);
}
//----------Form1.cs----------/
lvPluginInfo.Items.AddRange(PluginHandler.PluginList.ToArray());
lvPluginInfo.Items[0].SubItems.AddRange(PluginHandler.PluginList2.ToArray());
The output I get isn’t really what I want, it keeps adding subitems to the right instead of adding them next to eachother like:
item1a | item2a
item1b | item2b
…
Now I get:
item1a | item2a | item1b | item2b | …
Any ideas? Thanks!
You seem to be going about this in a very odd fashion. I assume this is what you’re intending to do?
The problem with the way you’re going about it is the following line:
lvPluginInfo.Items[0].SubItems.AddRange(PluginHandler.PluginList2.ToArray());. You’re adding all the subitems to the first ListViewItem. Adding the items outside of the loop doesn’t make much sense here.