943,885 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 639
  • VB.NET RSS
May 22nd, 2009
0

show related records on a new form

Expand Post »
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:

VB.NET Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
RobinTheHood is offline Offline
18 posts
since May 2009
May 22nd, 2009
0

Re: show related records on a new form

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
RobinTheHood is offline Offline
18 posts
since May 2009
May 23rd, 2009
0

Re: show related records on a new form

I have same proplem

I hope there is somebody help us...
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Wojood is offline Offline
1 posts
since May 2009
May 23rd, 2009
0

Re: show related records on a new form

Hope my friend, hope.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
RobinTheHood is offline Offline
18 posts
since May 2009
May 23rd, 2009
0

Re: show related records on a new form

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.
Reputation Points: 10
Solved Threads: 8
Junior Poster in Training
martonx is offline Offline
51 posts
since May 2008
May 24th, 2009
0

Re: show related records on a new form

I hope this will help you out:

Set SelectionMode to FullRowSelect

VB.NET Syntax (Toggle Plain Text)
  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")
Reputation Points: 10
Solved Threads: 1
Light Poster
Ossehaas is offline Offline
32 posts
since Jan 2008
May 25th, 2009
0

Re: show related records on a new form

In your second form make a constructor
VB.NET Syntax (Toggle Plain Text)
  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
VB.NET Syntax (Toggle Plain Text)
  1. Dim frm2 As New Form2
  2. frm2.Show(DataGridView1.CurrentRow)
Reputation Points: 11
Solved Threads: 49
Posting Whiz
jireh is offline Offline
316 posts
since Jul 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Stop Storyboard
Next Thread in VB.NET Forum Timeline: compare data valid or not





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC