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
I found out the hard way that if your listbox items are assigned via a data source
List workTables = hhsdbutils.GetWorkTableNames();
listBoxWork.DataSource = workTables;
...you have to unbind that before doing the removal:
listBoxWork.DataSource = null;
for (int i = listBoxWork.Items.Count - 1; i >= 0; --i)
{
if (listBoxWork.Items[i].ToString().Contains(listboxVal))
{
listBoxWork.Items.RemoveAt(i);
}
}
Without the "listBoxWork.DataSource = null;" line, I was getting, "Value does not fall within the expected range"