How to add subitems to a ListView?

前端 未结 3 1091
时光说笑
时光说笑 2021-01-05 17:57

I\'m trying to get the simplest possible example of a Listview with subitems working. But this code:

private void button1_Click(object sender, EventArgs e) {         


        
3条回答
  •  余生分开走
    2021-01-05 18:22

    You need to add another column for the SubItem. The reason why your subitem is not shown is because there is no column for it. Try this one.

    listView1.Columns.Add("Column 1"); // you can change the column name
    listView1.Columns.Add("Column 2");
    string[] strArr = new string[4] { "uno", "dos", "twa", "quad" };
    foreach (string x in strArr)
    {
        ListViewItem lvi = listView1.Items.Add(x);
        lvi.SubItems.Add("Ciao, Baby!");
    }
    

提交回复
热议问题