remove all collection items in collection when selected index of another collection changes

594 Views Asked by At

EDIT: I was missing a simple command. See answer below.

I'm developing a front end .NET application that will replace the current one that my organization currently uses, on a temporary basis, that is intended to be simple to use for the newer employees. This is in regards to a ticketing system. However, there is one function this application needs to perform, which is to 'classify' a problem that is reported. I have 3 collections: Service, Category, and Subcategory.

I currently have my program set up to add in available options for category and subcategory based on the values entered in previously.

if Convert.ToString(cboxservice.selecteditem) = 15k Then
cboxCategory.Items.Add("15k Request")
End If

And the like. Cboxservice is a combobox. When someone selects 15k for Service, 15k Request should show up under Category.

However, if I were to go to another service, and have other objects added to the Category field, categories from both objects would be present.

I need to remove all items in the collection before adding different items to the collection.

1

There are 1 best solutions below

2
On BEST ANSWER

Answer from NDJ, posted as comment.

why not just use cboxCategory.Items.Clear() ? if you really want to do this in a while loop removing them one by one, don't rely on an exception (they are expensive) - it'd be better to While cboxCategory.Items.Count > 0 – NDJ Dec 17 '14 at 8:44