C# removing items from listbox

后端 未结 16 2246
礼貌的吻别
礼貌的吻别 2020-12-02 00:12

I have a listbox being populated from a SQLDATA pull, and it pulls down some columns that i dont want like OBJECT_dfj, OBJECT_daskd. The key is all of these being with OBJE

16条回答
  •  [愿得一人]
    2020-12-02 00:35

    You can't use an enumerator, you have to loop using an index, starting at the last item:

    for (int n = listBox1.Items.Count - 1; n >= 0; --n)
    {
        string removelistitem = "OBJECT";
        if (listBox1.Items[n].ToString().Contains(removelistitem))
        {
            listBox1.Items.RemoveAt(n);
        }
    }
    

提交回复
热议问题