title: How do I pass datagridview data to controls on new form?
body: <p>How do I pass data from a datagridview control on one form to controls on another form?  I'm using the following code to retrieve information from my database - then when the user selects the appropriate row, I want controls on another form to display the data corresponding to that row.  Is this possible and if so, how do I do it?</p>
  
  <p><strong>Here's my code:</strong></p>
  
  <pre><code>If TextBox1.Text = "" Then
              MessageBox.Show("You must enter an account number to proceed!")
              TextBox1.Focus()
              Me.Refresh()
          Else
              Try
                  dbConn = New MySqlConnection("Server=" &amp; FormLogin.ComboBoxServerIP.SelectedItem &amp; ";Port=3306;Uid=123456;Password=234567;Database=accounting")
                  If dbConn.State = ConnectionState.Open Then
                      dbConn.Close()
                  End If
                  dbConn.Open()
                  Dim dbAdapter As New MySqlDataAdapter("SELECT ccNumber, ccExpireMonth, ccExpireYear, ccZipcode FROM cc_master WHERE customer_accountNumber = " &amp; TextBox1.Text, dbConn)
                  Dim myDatatable As New DataTable
                  dbAdapter.Fill(myDatatable)
                  If myDatatable.Rows.Count &gt; 0 Then
                      DataGridView1.DataSource = myDatatable
                  Else
                      MessageBox.Show("No Customer Records Found!  Please try again!")
                      TextBox1.Clear()
                      TextBox1.Focus()
                  End If
  
              Catch ex As Exception
                  MessageBox.Show("A DATABASE ERROR HAS OCCURED" &amp; vbCrLf &amp; vbCrLf &amp; ex.Message &amp; vbCrLf &amp; _
                              vbCrLf + "Please report this to the IT/Systems Helpdesk at Ext 131.")
              End Try
  
          End If
  </code></pre>