C# removing items from listbox

后端 未结 16 2310
礼貌的吻别
礼貌的吻别 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:40

    You can try this also, if you don't want to deal with the enumerator:

    object ItemToDelete = null;
    foreach (object lsbItem in listbox1.Items)
    {
       if (lsbItem.ToString() == "-ITEM-")
       {
          ItemToDelete = lsbItem;                                  
       }
    }
    
    if (ItemToDelete != null)
        listbox1.Items.Remove(ItemToDelete);
    

提交回复
热议问题