Solved

Data entry in a dialog form using multiple controls

Posted on 2004-09-13
5
178 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

770 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