| | |
show related records on a new form
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: May 2009
Posts: 17
Reputation:
Solved Threads: 0
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:
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.
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)
Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'TODO: This line of code loads data into the 'KeyData.Orders' table. You can move, or remove it, as needed. Me.OrdersTableAdapter.Fill(Me.KeyData.Orders) 'TODO: This line of code loads data into the 'KeyData.Customers' table. You can move, or remove it, as needed. Me.CustomersTableAdapter.Fill(Me.KeyData.Customers) 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.
•
•
Join Date: May 2008
Posts: 51
Reputation:
Solved Threads: 8
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.
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.
I hope this will help you out:
Set SelectionMode to FullRowSelect
you can use row.Cells(index) or row.Cells("ColumnName")
Set SelectionMode to FullRowSelect
VB.NET Syntax (Toggle Plain Text)
Private Sub myGridview_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles myGridview.SelectionChanged Dim gv As DataGridView = CType(sender, DataGridView) If gv.SelectedRows(0).Index > 0 Then Dim row As DataGridViewRow = gv.SelectedRows(0) Dim RecID As Integer = CType(row.Cells(0).Value, Integer) ' Open new form and pass the record id for the details End If End Sub
you can use row.Cells(index) or row.Cells("ColumnName")
In your second form make a constructor
so when calling your second form use the constructor you made and pass the row you haw selected
VB.NET Syntax (Toggle Plain Text)
Public Sub New(ByVal row As DataRow) Me.InitializeComponent() 'Add the other initialization here... 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)
Dim frm2 As New Form2 frm2.Show(DataGridView1.CurrentRow)
A conclusion is the place where you got tired of thinking. http://www.martin2k.co.uk/forums/index.php?showforum=4
http://www.a1vbcode.com/a1vbcode/vbforums/Forum3-1.aspx
http://www.developerfusion.co.uk/for...orum&ForumID=4
![]() |
Similar Threads
- displaying database records in new form (VB.NET)
- How can I show a form? (VB.NET)
- MS Access Forms - Deleting related records from other tables when deleting a record (MS Access and FileMaker Pro)
- How to show Access Table in a form (Visual Basic 4 / 5 / 6)
- subform without fields (MS Access and FileMaker Pro)
- combo box with related records (MS Access and FileMaker Pro)
- Datagridview problem (VB.NET)
- How do I show Tab control on my form in Win XP style Look? (VB.NET)
Other Threads in the VB.NET Forum
- Previous Thread: Stop Storyboard
- Next Thread: compare data valid or not
| Thread Tools | Search this Thread |
"crystal .net .net2005 30minutes 2008 access add advanced application array assignment basic binary box button buttons center click code combo connectionstring convert cpu data database databasesearch datagrid datagridview design designer dissertation dissertations dissertationthesis dosconsolevb.net editvb.net employees excel exists firewall folder image images isnumericfuntioncall listview login map math memory mobile module msaccess mssqlbackend mysql navigate net number opacity pan peertopeervideostreaming picturebox picturebox2 port print printpreview record regex reports" reuse right-to-left save savedialog search serial socket sorting sqldatbase sqlserver storedprocedure string temp textbox timer txttoxmlconverter upload useraccounts usercontol usercontrol vb vb.net vb.netcode vb.nettoolboxvisualbasic2008sidebar vbnet vista visual visualbasic visualbasic.net visualstudio.net web wpf xml





