show related records on a new form

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2009
Posts: 17
Reputation: RobinTheHood is an unknown quantity at this point 
Solved Threads: 0
RobinTheHood RobinTheHood is offline Offline
Newbie Poster

show related records on a new form

 
0
  #1
May 22nd, 2009
Hi all,

I've only just stared using VS2008 VB so please excuse me if this seems a very basic question. (I've amended my example to the Northwind Database to avoid any confusion)


WHAT I HAVE
I have a dataset called KeyData made up of two tables Customers and Orders.

I have two forms, one named MainForm that shows records from Customers in details view and the related Orders shown in GridView called OrdersDataGridView. The other form is called OrdersForm and is populated with the Orders table from the keydata dataset and shows records in details view.

When I navigate the MainForm customer records the correct orders are shown in the OrdersDataGridView. So far so good.

Here's the code that was generated when I dropped the tables within KeyData dataset onto the MainForm:

  1. Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2. 'TODO: This line of code loads data into the 'KeyData.Orders' table. You can move, or remove it, as needed.
  3. Me.OrdersTableAdapter.Fill(Me.KeyData.Orders)
  4. 'TODO: This line of code loads data into the 'KeyData.Customers' table. You can move, or remove it, as needed.
  5. Me.CustomersTableAdapter.Fill(Me.KeyData.Customers)
  6. End Sub


WHAT I WANT.
On clicking a recorded (or row) in OrdersDataGridView I want to open the second from (OrdersForm) and only show derails (in the OrdersForm) of the specific row that was clicked on the OrdersDataGridView. I'm sure everyone knows the related field in Orders in OrdersID

As I'll be opening the OrdersForm as a modal I don't need to close the MainForm.

Also, I’ll be using this method of showing details in various other parts my project. In some case I’ll want to show records that can be edited, in other cases I want the records to be read only and in one instance I’ll want to show a new record ready for data entry. In this case I want them to be read only, but it would be nice to know how I could change this on opening the form.

Sorry to be so long winded in the explanation but I wanted to be as clear as my knowledge allows.

Thank you in advance

PS For thos who surf the forums I did post this elsewhere but haven't got much help so far.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 17
Reputation: RobinTheHood is an unknown quantity at this point 
Solved Threads: 0
RobinTheHood RobinTheHood is offline Offline
Newbie Poster

Re: show related records on a new form

 
0
  #2
May 22nd, 2009
Hmm, No answers.
Maybe I've over-cooked the question.

Let me rephrase.
When I click a row in gridview how do I open another form and show a related record based on the common field OrdersID?

Thanks
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 1
Reputation: Wojood is an unknown quantity at this point 
Solved Threads: 0
Wojood Wojood is offline Offline
Newbie Poster

Re: show related records on a new form

 
0
  #3
May 23rd, 2009
I have same proplem

I hope there is somebody help us...
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 17
Reputation: RobinTheHood is an unknown quantity at this point 
Solved Threads: 0
RobinTheHood RobinTheHood is offline Offline
Newbie Poster

Re: show related records on a new form

 
0
  #4
May 23rd, 2009
Hope my friend, hope.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 51
Reputation: martonx is an unknown quantity at this point 
Solved Threads: 8
martonx martonx is offline Offline
Junior Poster in Training

Re: show related records on a new form

 
0
  #5
May 23rd, 2009
Hi,

You should use showdialog method for open the second form. You should make a property for second form, so you can give the actual OrderID through this property. On the second form you need to do data filtering (this is the easiest, but not so elegant), or a special SQL select method for get the correct details.

I hope, I could help you.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 10
Reputation: Ossehaas is an unknown quantity at this point 
Solved Threads: 0
Ossehaas's Avatar
Ossehaas Ossehaas is offline Offline
Newbie Poster

Re: show related records on a new form

 
0
  #6
May 24th, 2009
I hope this will help you out:

Set SelectionMode to FullRowSelect

  1. Private Sub myGridview_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles myGridview.SelectionChanged
  2.  
  3. Dim gv As DataGridView = CType(sender, DataGridView)
  4.  
  5. If gv.SelectedRows(0).Index > 0 Then
  6. Dim row As DataGridViewRow = gv.SelectedRows(0)
  7.  
  8. Dim RecID As Integer = CType(row.Cells(0).Value, Integer)
  9.  
  10. ' Open new form and pass the record id for the details
  11. End If
  12.  
  13. End Sub

you can use row.Cells(index) or row.Cells("ColumnName")
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 300
Reputation: jireh is an unknown quantity at this point 
Solved Threads: 42
jireh's Avatar
jireh jireh is offline Offline
Posting Whiz

Re: show related records on a new form

 
0
  #7
May 25th, 2009
In your second form make a constructor
  1. Public Sub New(ByVal row As DataRow)
  2. Me.InitializeComponent()
  3.  
  4. 'Add the other initialization here...
  5.  
  6. End Sub

so when calling your second form use the constructor you made and pass the row you haw selected
  1. Dim frm2 As New Form2
  2. frm2.Show(DataGridView1.CurrentRow)
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC