Can someone please, please, please give me the syntax in vb 2008 for referencing records on a parent form, I’ve been trying to do this for ages and can’t work it out or find help that answers this. I’m new to VS and vb2008 so please excuse any errors in describing my scenario.

· Form A is bound to a strongly typed Dataset named MASTERDATASET which comprises of multiple related sql server tables. One of the tables is named TBLCUSTOMER.

· TBLCUSTOMER details are displayed on form A in a Gridview named CUSTOMERGRIDVIEW

· Form B displays details from TBLCUSTOMER in detailview . The primary key is customerID.

When I click a row in CUSTOMERGRIDVIEW on form A I want to open form B and display records relating to that customer.

Please let me know if there’s insufficient details to answer this or if the problem is unclear.

Many thanks in advance

Hi,

(I hope understand your problem)

1)
You can use the event "CellClick" of the DataGridView in form A:

' in this code the primary key of the table is loaded in the first column, Me.DataGridView1.CurrentRow.Cells(0).Value

Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
Dim customerID_ As Integer = Me.DataGridView1.CurrentRow.Cells(0).Value
Dim Instance_FormB As New FormB(customerID_)
Instance_FormB.ShowDialog()
End Sub

2)

in Form B you can use this:


' Is the code of all class of Form B
Public Class FormB

Dim customer_ID As Integer

Private Sub FormB_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'in this place your have to fill the dadatGridView with the details from TBLCUSTOMER
End Sub


I want this help you... (sorry.....my english is not very good)


Public Sub New(ByVal customerID As Integer)
' This call is required by the Windows Form Designer.
InitializeComponent()
customer_ID = customerID
' Add any initialization after the InitializeComponent() call.
End Sub
End Class

Hi,

(I hope understand your problem)

1)
You can use the event "CellClick" of the DataGridView in form A:

' in this code the primary key of the table is loaded in the first column, Me.DataGridView1.CurrentRow.Cells(0).Value

Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
Dim customerID_ As Integer = Me.DataGridView1.CurrentRow.Cells(0).Value
Dim Instance_FormB As New FormB(customerID_)
Instance_FormB.ShowDialog()
End Sub

2)

in Form B you can use this:

' Is the code of all class of Form B

Public Class FormB

Dim customer_ID As Integer

Private Sub FormB_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'in this place your have to fill the dadatGridView with the details from TBLCUSTOMER
End Sub

Public Sub New(ByVal customerID As Integer)
' This call is required by the Windows Form Designer.
InitializeComponent()
customer_ID = customerID
' Add any initialization after the InitializeComponent() call.
End Sub
End Class

I want this help you... (sorry.....my english is not very good)

I'm geatful to you for taking the time to reply.

I'll be back at my project late tonight, Can't wait to try this out. Will get back to then and let you know how I got on.

Many, many thanks

Hi dlplenin

I tried your code as best as I could , knowing that I donlt fully understand how it works.

However, when opening formB the displayed record show always shows thfirst person in TblCustomers and not the row that I click on in FormA.

I'm pretty sure it's my lack of understanding of your code, so I'm going to carry on playing around with it, althoug at my current level of understanding I think it might tale a while.

Here's the entire code that I have for both formA and FormB. any assistance would of course be appreciated.

Public Class FormA

Private Sub FormA_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'CustomerDataSet.TblCustomers' table. You can move, or remove it, as needed.
Me.TblCustomersTableAdapter.Fill(Me.CustomerDataSet.TblCustomers)

End Sub


Private Sub TblCustomersDataGridView_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
Dim customerID_ As Integer = Me.DataGridView1.CurrentRow.Cells(0).Value
Dim Instance_FormB As New FormB(customerID_)
Instance_FormB.ShowDialog()

End Sub
End Class

Public Class FormB
Dim customer_ID As Integer
Public Sub New(ByVal customerID As Integer)
' This call is required by the Windows Form Designer.
InitializeComponent()
customer_ID = customerID
' Add any initialization after the InitializeComponent() call.
End Sub

Private Sub FormB_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'CustomerDataSet.TblCustomers' table. You can move, or remove it, as needed.
Me.TblCustomersTableAdapter.Fill(Me.CustomerDataSet.TblCustomers)

End Sub
End Class

You have to create a new query in the dataset, this query have to have a parameter, something like this (where customerID=@id):
SELECT TBLCUSTOMER.*
FROM TBLCUSTOMER
where customerID=@id

so, in the Load event of the FormB you can use this:

Private Sub FormB_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'in this place your have to fill the dadatGridView with the details from TBLCUSTOMER
Dim a As New DataSet1.TBLCUSTOMERDataTable
Dim b As New DataSet1TableAdapters.TBLCUSTOMER1TableAdapter
b.FillBy(a, customer_ID)
'in this case I use the DataGridView to show the records
Me.DataGridView1.DataSource = a
End Sub


in this example the name of dataset is DataSet1.xsd and the name of the query is FillBy

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.