如何将多个列表的内容添加到 ListView 项和子项中?

How do you add the contents of multiple lists into ListView items and subitems?

我有几个列表,其中包含赛事名称和赛事类型,无论是团队赛事还是个人赛事。每个事件的名称和事件类型用分号分隔。

Properties.Settings.Default.eventName = "Chess;Football;Paintball;Swimming";
Properties.Settings.Default.eventName = "indiv;team;team;indiv";
List<string> eventName = Properties.Settings.Default.eventName.Split(';').ToList();
List<string> eventType = Properties.Settings.Default.eventType.Split(';').ToList();

我想要列表形式的这些,以便以后可以轻松添加更多事件。如何将这些添加到以下配置的 ListView 中,事件名称作为项目,事件类型作为子项目?

 _________________________
| Name       | Type       | <--- column names
|____________|____________|
| Chess      | Individual |
|____________|____________|
| Football   | Team       |
|____________|____________|
| Paintball  | Team       |
|____________|____________|
| Swimming   | Individual |
|____________|____________|

到目前为止我有什么。这只是添加项目,不确定如何添加子项目,因为它说“ListView 不包含子项目的定义”。

foreach (string eventNameItem in eventName)
{
    lvEvents.Items.Add(eventNameItem);
}

使用以下代码。我认为它有效。

Properties.Settings.Default.eventName = "Chess;Football;Paintball;Swimming";
Properties.Settings.Default.eventType = "indiv;team;team;indiv";
List<string> eventName = Properties.Settings.Default.eventName.Split(';').ToList();
List<string> eventType = Properties.Settings.Default.eventType.Split(';').ToList();

for(int i=0;i< eventName.Count; i++)
{
    string[] row = { eventName[i], eventType[i] };
    ListViewItem item = new ListViewItem(row);
    listView1.Items.Add(item);
}

或使用

//Width of -2 indicates auto-size.
listView1.Columns.Add("eventName", -2, HorizontalAlignment.Left);
listView1.Columns.Add("eventType", -2, HorizontalAlignment.Left);

for (int i = 0; i < eventName.Count; i++)
{
    string[] row = { eventName[i], eventType[i] };
    ListViewItem item = new ListViewItem(row);
    listView1.Items.Add(item);
 }