Add item to Listview control

后端 未结 6 1612
-上瘾入骨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条回答
  •  死守一世寂寞
    2020-11-28 07:17

    Add items:

    arr[0] = "product_1";
    arr[1] = "100";
    arr[2] = "10";
    itm = new ListViewItem(arr);
    listView1.Items.Add(itm);
    

    Retrieve items:

    productName = listView1.SelectedItems[0].SubItems[0].Text;
    price = listView1.SelectedItems[0].SubItems[1].Text;
    quantity = listView1.SelectedItems[0].SubItems[2].Text;
    

    source code

提交回复
热议问题