Add item to Listview control

后端 未结 6 1608
-上瘾入骨i
-上瘾入骨i 2020-11-28 06:31

I have a listview in c# with three columns and the view is details. I need to add a item to each specific column but I am having a hard time with this. I have t

6条回答
  •  萌比男神i
    2020-11-28 07:23

    The first column actually refers to Text Field:

      // Add the pet to our listview
        ListViewItem lvi = new ListViewItem();
        lvi.text = pet.Name;
        lvi.SubItems.Add(pet.Type);
        lvi.SubItems.Add(pet.Age);
    
        listView.Items.Add(lvi);
    

    Or you can use the Constructor

     ListViewItem lvi = new ListViewItem(pet.Name);
     lvi.SubItems.Add(pet.Type);
     ....
    

提交回复
热议问题