?
Solved

VB.NET FORM/SUBFORM

Posted on 2005-03-05
7
Medium Priority
?
608 Views
Last Modified: 2012-08-14
In MSAccess there is a main form and child form where one record displayed on the main form could have one to many records displayed in the child subform.

I would like to know if there is an equivalent in VB.NET. if so, a little be example would be a good help.



thanks
0
Comment
Question by:Chuckbuchan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 13467402
VB.NET does NOT have a direct equivalent to the SUBFORM in Access.  You would need to add your own code to accomplish the same effect.

In Access you can create the 'subform' as if it were a form in its own right, and then 'embed' it in the Main Form, thereby making is a sub-form (you then set the Master and child linking fields).  .NET has no such concept (you cannot 'embed' one form in another form).

AW
0
 
LVL 15

Expert Comment

by:Ralf Klatt
ID: 13467679
Hi,

@Arthur_Wood ... couldn't, with some minor changes, a MDI Parent with some children in VB.NET do what Chuckbuchan asked for?


Best regards,
Raisor
0
 

Author Comment

by:Chuckbuchan
ID: 13468428
It doesn't have to be the same, but it displays the data the same way.
For instance in the VB.net form, we can have a combobox and some other textboxes that display a data of one record and in the same form we can have kind of datagrid that should display all the records related to the record displayed on the form.

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 15

Accepted Solution

by:
Ralf Klatt earned 750 total points
ID: 13468592
Hi,

I think that, if you're using a form in VB.NET (setting the IsMdiContainer property to true) you may call as many child forms as you like.

If a child form has a public variable like "myRecordID" you can set that variable to any value that your data logic needs to set it to. Take this as an example:

        Dim myProvider As New frmProvider()
        myProvider.myProviderID = 1
        myProvider.MdiParent = Me
        myProvider.Show()
        myProvider = Nothing

... where myProviderID is a public variable in the Child Form!

When loading "frmProvider" this is what's necessary to work with the myProviderID variable:

    Private Sub frmProvider_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            Me.LoadDataSet()
        Catch eLoad As System.Exception
            System.Windows.Forms.MessageBox.Show(eLoad.Message)
        End Try
        Select Case myProviderID
            Case 0
                Me.objdsProvider_PositionChanged()
            Case Else
                btnNavFirst.Enabled = False
                btnNavNext.Enabled = False
                btnNavPrev.Enabled = False
                btnLast.Enabled = False
                btnDelete.Enabled = False
                btnCancel.Enabled = False
                btnCancelAll.Enabled = False
                btnUpdate.Enabled = False
                btnAdd.Enabled = False
                Me.objdsProvider_ChangePosition()
        End Select
    End Sub


... what you can see from this short example is, that the myProviderID variable is already accessible on the Load Event of the child form ... and that it has an impact on how the DataSet Position is set (and how some controls are meant to behave) when loading the Child Form.

This is surely just a limited glance on what we're using in production ... while the child form has been pre-generated using the VB.NET Data Form Wizard ... where you may also define a DataGrid instead of other controls ...


Best regards,
Raisor
0
 
LVL 15

Expert Comment

by:Ralf Klatt
ID: 13468656
Hi,

i just thought I'd give you another example of the impact MyProviderID = 0 Or Else has:

Case 0:

    Private Sub objdsProvider_PositionChanged()
        Me.lblNavLocation.Text = (((Me.BindingContext(objdsProvider, "tbProviders").Position + 1).ToString + " of  ") _
                    + Me.BindingContext(objdsProvider, "tbProviders").Count.ToString)

    End Sub

... that is the standard way of handling the position (created by the Data Form Wizard)

Case Else:

    Private Sub objdsProvider_ChangePosition()
        Dim i As Integer
        For i = 1 To Me.BindingContext(objdsProvider, "tbProviders").Count
            'MessageBox.Show(objdsProvider.Tables(0).Rows(i - 1).Item(1))
            If objdsProvider.Tables(0).Rows(i - 1).Item(0) = myProviderID Then
                Me.objdsProvider_PositionChanged()
                Exit For
            Else
                Me.BindingContext(objdsProvider, "tbProviders").Position = (Me.BindingContext(objdsProvider, "tbProviders").Position + 1)
                Me.objdsProvider_PositionChanged()
            End If
        Next
    End Sub

... is the position where we want the DataSet (record) to be shown when the Data Form is called! <- could also be used for different filters (stored procedures) or in whatever way you may use it.


Best regards,
Raisor
0
 

Author Comment

by:Chuckbuchan
ID: 13470681
Hi raisor,
I was in the middle of doing something similar to what I was looking for , when you posted your last comment. here is what I am doing, though it's not finished yet.
the example is based on Nortwind database, so I am sure you have a copy of it.
I put  02 datagrids on the form

datagrid1 has:
datasource:DSorders which is a dataset
data member: Orders
datagrid2 has
datasource:DSdetails which is a dataset
data member:products

**As you can notice if you check that database, the Orders and the products table have OrderID as common field. So what I am trying to do is: when I put a cursor on any row of the datagrid1, the datagrid2 should show all the records corresponding to the OrderID of the datagrid1

Below is part of operation. I hope this will give you an idea on how to get the datagrid2 showing the corresponding records, based on the OrderID that is selected on the datagrid1.




Private Sub DataGrid1_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.CurrentCellChanged
        Dim row As Integer = Me.DataGrid1.CurrentRowIndex
        Dim ordid As Integer = Me.DataGrid1.Item(row, 0)
        Me.Details.SelectCommand.Parameters("orderID").Value = ordid
        Me.DsOrders1.Clear()
        Me.Orders.Fill(Me.DsDetails1)
    End Sub
0
 
LVL 15

Expert Comment

by:Ralf Klatt
ID: 13470941
Hi,

I have a small test application somewhere where the Northwind DB is used for testing purposes ... exactly using Orders and OrderDetails ...

But I think we can get to the point without using a quite complex sample application just to explain a simple task ...

If you just implement a myOrderID variable in a Child Form and set it to the value of "Me.DataGrid1.Item(row, 0)" using the CurrentCellChanged Event of DataGrid1 ... you'd be able to access that value in the Child Form's Load Event -> placing it right at "Me.Details.SelectCommand.Parameters("orderID").Value = Me.myOrderID" and performing the yourDataAdapter.Fill(yourDataSet) right there, so ... assuming that DataGrid1.DataSource (on Child Form) =  yourDataAdapter and assuming you perform a DataGrid1.Refresh() on the Child Form you should already have what you're looking for ... if you dock your datagrid on the child form to the child form size and if you dock the child form itself to the mdi form bounds -> it'll look like a normal subform in MS Access.


Best regards,
Raisor
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Six Sigma Control Plans

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question