B
BobRoyAce
Let's say that I have a form on which a user can edit a Customer
record. On the form I have a module level variable as follows:
Private mo_CurrentCustomer As Customer
where Customer is a class defined in the system. After the user makes
all of their data entries on the form, I move the data they entered
into the properties of the Customer object and save the data if all is
well with the data they entered.
Well, to do this type of thing in the past, I would use two Sub's on
every form like follows:
Private Sub UpdateFormToReflectCurrentCustomer()
txtCustomerName.Text = mo_CurrentCustomer.CustomerName
If (mo_CurrentCustomer.DOB.HasValue) Then
deDOB.DateTime = mo_CurrentCustomer.DOB
Else
deDOB.EditValue = System.DBNull.Value
End If
'...etc.
End Sub
Private Sub UpdateCurrentCustomerToReflectForm()
mo_CurrentCustomer.CustomerName = txtCustomerName.Text
If (Not IsDBNull(deDOB.DateTime)) Then
mo_CurrentCustomer.DOB = deDOB.DateTime
Else
mo_CurrentCustomer.DOB = Nothing
End If
'...etc.
End Sub
Well, this has worked fine for me. However, I just noticed that edit
controls can be bound to object properties like follows:
txtCustomerName.DataBindings.Add("Text", mo_CurrentCustomer,
"CustomerName")
Well, that seems pretty slick and easier to code. However, I am
wondering if there are any downsides to this.
For example, how will certain controls handle NULL values in
properties?
What happens if a control has a NULL value and is bound to a property
of the object that is not NULLABLE?
For a DATE control, which property of the control would I bind to a
date field of an object?
record. On the form I have a module level variable as follows:
Private mo_CurrentCustomer As Customer
where Customer is a class defined in the system. After the user makes
all of their data entries on the form, I move the data they entered
into the properties of the Customer object and save the data if all is
well with the data they entered.
Well, to do this type of thing in the past, I would use two Sub's on
every form like follows:
Private Sub UpdateFormToReflectCurrentCustomer()
txtCustomerName.Text = mo_CurrentCustomer.CustomerName
If (mo_CurrentCustomer.DOB.HasValue) Then
deDOB.DateTime = mo_CurrentCustomer.DOB
Else
deDOB.EditValue = System.DBNull.Value
End If
'...etc.
End Sub
Private Sub UpdateCurrentCustomerToReflectForm()
mo_CurrentCustomer.CustomerName = txtCustomerName.Text
If (Not IsDBNull(deDOB.DateTime)) Then
mo_CurrentCustomer.DOB = deDOB.DateTime
Else
mo_CurrentCustomer.DOB = Nothing
End If
'...etc.
End Sub
Well, this has worked fine for me. However, I just noticed that edit
controls can be bound to object properties like follows:
txtCustomerName.DataBindings.Add("Text", mo_CurrentCustomer,
"CustomerName")
Well, that seems pretty slick and easier to code. However, I am
wondering if there are any downsides to this.
For example, how will certain controls handle NULL values in
properties?
What happens if a control has a NULL value and is bound to a property
of the object that is not NULLABLE?
For a DATE control, which property of the control would I bind to a
date field of an object?