Data bind problem setting default field values

C

cweibel

This should be an easy problem for those with far more knowledge than
myself with databinding.

I have a VB.NET 2005 windows form with several checkboxes, textboxes
and datepickers which are bound to a single dataset (running SQL Server
2000). The form also contains a record navigation bar to move through
the records. When the form loads, after assigning the table adapter, I
call the AddNew event which calls a function I have to set the default
values for the checkboxes, textboxes and datepickers. After adding all
of the required data and clicking Save in the navigator toolbar I click
AddNew which again calls my function to assign default values. This is
where things get weird: after assigning all the field values and
clicking save for the second time, if the datepicker date did not
change from the previously added record then NULL is saved to the
database.

It seems that there is some internal event that needs to kick off to
force the value in the datepicker back to the databind/datatable.

Ideas?

Thanks in advance,
CW
 
C

cweibel

Continued...
Here is the code I am using:

'Form load
Private Sub Adjustment_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Me.TblAdjustmentTableAdapter.Fill(Me.PBDVDataSet.tblAdjustment)
BindingNavigatorAddNewItem1_Click(sender, e)
End Sub

Private Sub BindingNavigatorAddNewItem1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
BindingNavigatorAddNewItem1.Click
TblAdjustmentBindingSource.AddNew()
InitializeNewRecord()
End Sub


'Sets defaults when "Add New" is clicked
Public Sub InitializeNewRecord()

AdjAddedDTTMDateTimePicker.Value = Today
AdjStartDTDateTimePicker.Value = Today
cmbUserFK.SelectedValue = UserID
chkAllowMultiMatch.Checked = False
chkExpires.Checked = True
AdjAmountTextBox.Text = "0"

End Sub

Private Sub SaveToolStripButton1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
SaveToolStripButton1.Click

Me.TblAdjustmentBindingSource.EndEdit()

Me.TblAdjustmentTableAdapter.Update(Me.PBDVDataSet.tblAdjustment)
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top