Hope I can do this, I’m still newish to C#…
I have a bunch of lists of strings that I want to put into different columns of a Listview. I’m able to get the first column to populate using the code shown below, but can’t figure out how to do this for the subsequent columns.
List<string> l_Time = new List<string>();
//l_Time is populated by a method
foreach (string elem in l_Time)
{
listViewEvents.Items.Add(new ListViewItem(elem));
}
listViewEvents is my ListView
Any help is appreciated.
Edit:
Both shown solutions work to store my lists across a row, which I was able to find a lot online. I want to be able to store each list down it’s own column. Is this possible?
Try this:
The
ListViewItemclass has a constructor that takes an array of strings. When that constructor is used, then the other strings will appear in the other columns.If you want to do more with the other columns, then the list view item has a
SubItemsproperty that holds a collection ofListViewItem.ListViewSubItemobjects. You can create these with whatever values you want and add them to the list view item objects.UPDATE
Here’s a way to display lists of strings in separate columns:
Called like this: