I'm using .net CF 3.5 to develop an application for Windows Mobile 5.0
I have a ListBox with a list of numbers in. When they click on a number in the list, it should be deleted from the list. I can get the selected item's index just fine from the list - However, I cannot seem to delete it without the application crashing. There are no errors, it will just exit with code 0.
private void DeleteOrder(object sender, EventArgs e) {
string s = (string) orders_list.SelectedItem;
int size = orders_list.Items.Count;
bool con = true;
for (int i = 0; i < size; i++) {
Debug.Write("\nIS: " + i + "\n");
if (con) {
if (s != null || s != "") {
if (orders_list.GetItemText(orders_list.Items[i]) != null) {
if (orders_list.GetItemText(orders_list.Items[i]).ToString() == s) {
if (orders_list.Items[i] != null) {
Debug.Write("ORDER IS : " + orders_list.Items[i].ToString());
orders_list.Items.Remove(orders_list.Items[i].ToString());
}
con = false;
}
}
}
}
}
input_scan.Text = "";
this.BackColor = Color.Lime;
input_scan.Focus();
}
}
}
As you can see, I've tried doing
orders_list.Items.Remove(orders_list.Items[i].ToString());
to see if I can remove the string object and I've tried using RemoveAt()
to remove by index, but each time the application will keep crashing.
Any help would be appreciated as something so simple such as removing from a collection has become rather a challenge.