Ghanisen
asked on
Data entry in a dialog form using multiple controls
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.
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.
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.
Public don As New Donnees
in you entry form
this way you don't need a propery, don becomes a property of the form.
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
'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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi wguerram,
Thanks, it works.
Thanks, it works.
ASKER
Sorry I'm using 3 textboxes and 1 DateTimePicker.
Thanks