title: VB .Net Multiple Instances of same for with Events
body: <p>I am trying to open multiple instances of the same form based on rows selected from a DataGridView.
  My current code works, but waits for each form to close before going onto the next.
  I need to open the forms at the same time, but still have them report back to the main form via events.</p>
  
  <pre><code>Public Class frmARLog
      Private WithEvents edit As frmEditARLog
      'WithEvents: indicate that we want to receive events raised by this object
  
      Sub New()
  
          ' This call is required by the designer.
          InitializeComponent()
  
          ' Add any initialization after the InitializeComponent() call.
          fill()
      End Sub
  
      Sub fill()
          Dim AR As AltARLog = New AltARLog
  
          dgvARLog.DataSource = AR.getTable
  
      End Sub
  
      Private Sub btnEdit_Click(sender As Object, e As EventArgs) Handles btnEdit.Click
          Dim iRowIndex As Integer
          For i As Integer = 0 To dgvARLog.SelectedCells.Count - 1
  
              iRowIndex = dgvARLog.SelectedCells.Item(i).RowIndex
              openEditForm(dgvARLog.Rows(iRowIndex).Cells(0).Value.ToString, iRowIndex)
          Next
      End Sub
  
      Sub openEditForm(arid As Integer, row As Integer)
          edit = New frmEditARLog(arid)
          AddHandler edit.FormClosing, AddressOf ItIsClosing
          AddHandler edit.FormClosed, AddressOf ItIsClosed
          edit.ShowDialog(Me)
      End Sub
  
      Private Sub ItIsClosing(sender As Object, e As FormClosingEventArgs)
          If edit.Successful Then
              fill()
          End If
          RemoveHandler edit.FormClosing, AddressOf ItIsClosing
      End Sub
  
      Private Sub ItIsClosed(sender As Object, e As FormClosedEventArgs)
          RemoveHandler edit.FormClosed, AddressOf ItIsClosed
          edit = Nothing
      End Sub
  End Class
  </code></pre>