Solved

Data entry in a dialog form using multiple controls

Posted on 2004-09-13
5
180 Views
Last Modified: 2010-04-23
Hi,

I want to use a Windows form (frmSaisieDialog) to enter a new record by returning entered data to the parent form (frmParent), and also to update an existing record from data sent by the parent form (frmParent) to the data entry form frmSaisieDialog). I'm using 4 textboxes to enter/display data in frmParent.

To do this in one direction, that is data entry, it is straithforward using an object (Public Class Donnees)to store the data:

Public ReadOnly Property Donnees() As Donnees
        Get
            Dim don As New Donnees
            don.Nom = Me.txtNom.Text
            don.Prenom = Me.txtPrenom.Text
            don.Naissance = Me.dtpNaissance.Value
            don.Charge = Me.txtCharge.Text
            Return don
        End Get
    End Property

Public Class Donnees

    Public Nom As String
    Public Prenom As String
    Public Naissance As Date
    Public Charge As Integer

End Class

This is fine for entering a new record, but it doesn't allow to display data sent from the parent form (for updating) because the public property Donnees is ReadOnly.

If I remove the ReadOnly to get the Get and Set sequence I obtain this:

Public Property Donnees() As Donnees
        Get
            Dim don As New Donnees
            don.Nom = Me.txtNom.Text
            don.Prenom = Me.txtPrenom.Text
            don.Naissance = Me.dtpNaissance.Value
            don.Charge = Me.txtCharge.Text
            Return don
        End Get
        Set(ByVal Value As Donnees)


        End Set
    End Property

The problem is how to write the SET part to be able to send data from the parent form for updating.

Any help shall be greatly appreciated.
0
Comment
Question by:Ghanisen
  • 3
  • 2
5 Comments
 

Author Comment

by:Ghanisen
ID: 12047610
Hi,

Sorry I'm using 3 textboxes and 1 DateTimePicker.

Thanks
0
 
LVL 8

Expert Comment

by:wguerram
ID: 12048199
Declare donees var as public

Public don As New Donnees

in you entry form

this way you don't need a propery, don becomes a  property of the form.
0
 
LVL 8

Expert Comment

by:wguerram
ID: 12048256
or if wnat to do it via the property this is the code:

'Form declaration section
private  don As New Donnees

public Property Donnees() As Donnees
        Get
            don.Nom = Me.txtNom.Text
            don.Prenom = Me.txtPrenom.Text
            don.Naissance = Me.dtpNaissance.Value
            don.Charge = Me.txtCharge.Text
            Return don
        End Get
        Set(ByVal Value As Donnees)
            don.Nom = Value.Nom
            don.Prenom = Value.Prenom
            don.Naissance = Value.Naissance
            don.Charge = Value.Charge
        End Set
    End Property

So before you call your Entry form do this:

dim MyDon as new Donnees

'Initialize Don members from you parent form values
MyDon.Nom = 'Nom'

MyEntryForm.Donnees = MyDon
MyEntryForm.ShowDialog
0
 
LVL 8

Accepted Solution

by:
wguerram earned 500 total points
ID: 12048282
Sorry instead of assigning the values to the class, you want them in the textbox, so here is the code for the property:

In the Set statement

public Property Donnees() As Donnees
        Get
            don.Nom = Me.txtNom.Text
            don.Prenom = Me.txtPrenom.Text
            don.Naissance = Me.dtpNaissance.Value
            don.Charge = Me.txtCharge.Text
            Return don
        End Get
        Set(ByVal Value As Donnees)
            Me.txtNom.Text = Value.Nom
            Me.txtPrenom.Text = Value.Prenom
            Me.dtpNaissance.Value = Value.Naissance
            Me.txtCharge.Text = Value.Charge
        End Set
    End Property
0
 

Author Comment

by:Ghanisen
ID: 12048747
Hi wguerram,

Thanks, it works.
0

Featured Post

Technology Partners: 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

Suggested Solutions

Title # Comments Views Activity
vb.net class 3 28
How to duplicate form in Visual Studio 2015 2 89
Using/Import statement in code doesn't see reference of dll just added. 3 25
Need help with a query 3 36
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

679 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