Clearing a Collection

andrew104

Newcomer
Joined
Nov 14, 2002
Messages
9
How do you clear a collection consisting of labels and text boxes?

me.collection1.clear
or
Clear(collection1)

do not work. Thanks.
 
I assume you're using the VB.NET Collection class. You should really try and use one of the .NET collection classes under System.Collections.

Anyway, since the VB.NET Collection class has no clear method it looks like you'll have to loop through it to clear it:

Visual Basic:
Do While myCollection.Count <> 0
  myCollection.Remove(0)
Loop
 
Ok, I STILL cannot get the stupid clear collection thing. Here is exactly what I need to do.

When the user clicks the ClearButton,
The InputTextBox should clear along with all of the display labels
The focus should return to the InputTextBox and
The ClearLabel should be disabled.
The Clear Routine must be written using collections and a For/Each loop.
To do this, create a collection of all display labels and use the loop to clear them.


None of the suggestions below (although appreciated) worked.
 
Sounds like someone has a homework assignment. ;)

Assuming I read your post right...

Visual Basic:
Dim l as Label
For Each l In YourLabelCollection
    l.Text = ""
Next

InputTextBox.Text = ""
InputTextBox.Focus()
ClearLabel.Enabled = False
 
Back
Top