Hello:
I have read a few tutorials. I would like to pass data between containers on forms. I have read three articles on it, but nothing I'm doing is working out. In fact, I cannot even get the instantiated form to show now, which was not the case earlier.
There are two forms, frmRequest and frmHistory.
When selecting the History button on frmRequest, this code is run:
And this is not even working right now.
Once in the frmHistory form, I want to pull data from the frmRequest form.
On Load, the form calls the LoadHistory() Sub.
Next, there is a button on the frmHistory form to push the row from the DataGridView back to the various controls on the frmRequest form.
INDEX is a Public Variable
And when clicking on the DataGridView, INDEX is defined:
Is there a valid tutorial on this concept of passing data between forms? Beat practice, etc.??
Much Thanks!
I have read a few tutorials. I would like to pass data between containers on forms. I have read three articles on it, but nothing I'm doing is working out. In fact, I cannot even get the instantiated form to show now, which was not the case earlier.
There are two forms, frmRequest and frmHistory.
When selecting the History button on frmRequest, this code is run:
Code:
Private Sub cmdHistory_Click(sender As Object, e As EventArgs) Handles cmdHistory.Click
Dim frmH As New frmHistory
frmH.Show()
End Sub
Once in the frmHistory form, I want to pull data from the frmRequest form.
On Load, the form calls the LoadHistory() Sub.
Code:
Private Sub frmHistory_Load(sender As Object, e As EventArgs) Handles Me.Load
LoadHistory()
End Sub
Code:
Private Sub LoadHistory()
Dim frmR As New frmRequest()
frmR.Show()
Dim Requester As String = frmR.cboRequestor.Text
MessageBox.Show(Requester)
Dim connectionString As String = "Data Source=sage\SQLEXPRESS;Initial Catalog=PurchasingRequest;persist security info=True;Integrated Security=SSPI;"
Dim sql As String = "SELECT Parts.PN, Parts.Description, Parts.LongDescription, Parts.UM, Parts.Vendor, Parts.VendorPN, Parts.Qty, Parts.Notes " &
"FROM Parts INNER Join " &
"Request On Parts.RequestID = Request.ID " &
"WHERE (Request.Requester = '" & Requester & "') " &
"ORDER BY Parts.Description "
Debug.WriteLine(sql)
Using cn As New SqlConnection(connectionString)
Using cmd As New SqlCommand(sql, cn)
cmd.CommandType = CommandType.Text
Using sda As New SqlDataAdapter(cmd)
Using dt As New DataTable()
sda.Fill(dt)
dgvHistory.DataSource = dt
End Using
End Using
End Using
End Using
End Sub
Code:
Private Sub cmdAddSelected_Click(sender As Object, e As EventArgs) Handles cmdAddSelected.Click
Dim frmR As New frmRequest()
frmR.Show()
Dim SelectedRow As DataGridViewRow
SelectedRow = dgvHistory.Rows(INDEX)
frmR.cboPN.Text = SelectedRow.Cells(0).Value
frmR.cboPD.Text = SelectedRow.Cells(1).Value
frmR.cboUM.Text = SelectedRow.Cells(3).Value
frmR.cboVendor.Text = SelectedRow.Cells(4).Value
frmR.cboVendorPN.Text = SelectedRow.Cells(5).Value
frmR.txtNotes.Text = SelectedRow.Cells(7).Value
End Sub
Code:
Public INDEX As Integer
Code:
Private Sub dgvHistory_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvHistory.CellClick
INDEX = e.RowIndex
End Sub
Is there a valid tutorial on this concept of passing data between forms? Beat practice, etc.??
Much Thanks!