C# removing items from listbox

c#

Solution

Sorry guys i had to adjust the string

sqldatapull = dr[0].ToString();
                if (sqldatapull.StartsWith("OBJECT"))
                {
                    sqldatapull = "";
                }
                listBox1.Items.Add(sqldatapull);
                for (int i = listBox1.Items.Count - 1; i >= 0; i--)
                {
                    if (String.IsNullOrEmpty(listBox1.Items[i] as String))
                        listBox1.Items.RemoveAt(i);
                }
            }

Problem

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 OBJECT_, is there a way to remove these from the listbox? I cannot change my SQL statement. i tried this: ``` foreach (string item in listBox1.Items) { string removelistitem = "OBJECT"; if(item.Contains(removelistitem)) { listBox1.Items.Remove(item); } } ``` but it gave me the error: List that this enumerator is bound to has been modified. An enumerator can only be used if the list does not change.

Original source

Related problems