How prevent duplicate items listView C#

后端 未结 5 691
终归单人心
终归单人心 2020-12-19 07:50

I am using Windows Forms. With this code I add items to listView from comboBox.

ListViewItem lvi = new ListViewItem();         


        
5条回答
  •  无人及你
    2020-12-19 07:57

    if (!listView1.Items.Any(i => i.text == lvi.text))
    {
        listView1.items.Add(lvi)
    }
    

    I'm just guessing on the text property, but I'm pretty sure that's there.

    Alternatively - just have a List and use it as a data source for your list.

提交回复
热议问题