This code was taken from a forms collection that I use to create multiple instances of a form. For example, the application allows several customer records to be opened at once, but only one instance of every customer. So the full version has a method that allows you to check the object stored in each form's tag property.

When I open a customer record, I store the datarow from the dataset (or you could store just the customer's id) in the tag property. Then, I have a method in the forms collection called IsInstanceInCollection which goes something like this:

VB Code:
  1. Public Function IsInstanceInCollection(ByVal formName As String, ByVal row As DataRow) As Form
  2.         Dim item As Form
  3.         Dim formRow As DataRow
  4.         Dim counter As Integer
  5.         Try
  6.             'loop through the forms collection
  7.             For Each item In list
  8.                 If item.Name.ToLower = formName.ToLower Then
  9.                     'if the form names match then retrieve the row
  10.                     formRow = CType(item.Tag, DataRow)
  11.                     'if the items in the left most columns match then return the form as the correct item
  12.                     If formRow(0) = row(0) Then
  13.                         Return item
  14.                     End If
  15.                 End If
  16.             Next
  17.         Catch ex As Exception
  18.             MessageBox.Show("Error locating the specified instance of " & formName)
  19.             Return Nothing
  20.         Finally
  21.             formRow = Nothing
  22.             item = Nothing
  23.         End Try
  24.     End Function

This returns the instance of the form if found.

The calling code is an If statement that checks to see if the method returns something and if not, will create a new instance to display to the user and stores the relevant data row in the tag property as the new form is loaded.

It is overloaded to work in a variety of different ways.

A cut down version of this to work with the code that staticbob wrote would go something like this:

VB Code:
  1. Public Sub Remove(ByVal formTagObject As Object)
  2.         Dim frm As Form
  3.         For Each frm In MyBase.InnerList
  4.             If frm.Tag = formTagObject Then
  5.                 MyBase.InnerList.Remove(frm)
  6.                 Exit For
  7.             End If
  8.         Next
  9.     End Sub

To use this, I just created a unique string to store in each new form's tag object when instantiating and adding them to the collection.

Hope this clarifies things