C# removing items from listbox

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

    You can't modify a collection while you're iterating over it with foreach. You might try using a regular for() statement.

    You may need to iterate backwards from the end of the collection to make sure you cover every item in the collection and don't accidentally overrun the end of the collection after removing an item (since the length would change). I can't remember if .NET accounts for that possibility or not.

提交回复
热议问题