I wrote an application in .NET 2003, everything worked fine for several
weeks. This application has several text boxes and a detail grid. I
put navigation buttons on the form to move to the next record, which
will also change the data in the grid. I didn't make any changes to
the application, but all of a sudden, the detail grid quit updating
with changes to the position of the master. If I just did it wrong in
the first place and it should have never worked, then that's the way it
is, but I would like to know what I did wrong, and maybe some ideas of
why it would all of a sudden decide to stop working.
Thank you
Kalvin
Here is my code:
'***** CODE STARTS HERE
Public Function GetAllLabs() As DataSet
Dim DS As DataSet
DS = SqlHelper.ExecuteDataset(ConnectionString _
, CommandType.StoredProcedure _
, GET_ALL_LABS)
DS.Tables(0).TableName = LabsTable
DS.Tables(LabsTable).PrimaryKey = New DataColumn()
{DS.Tables(LabsTable).Columns("LabID")}
GetChild(DS)
DS.Relations.Add("LabsToPVS" _
, DS.Tables(LabsTable).Columns("LabID") _
, DS.Tables(CHILD).Columns("LabID"))
Return DS
End Function
Public Sub GetChild(ByRef DS As DataSet)
SqlHelper.FillDataset(ConnectionString _
, CommandType.StoredProcedure _
, GET_CHILDREN _
, DS _
, New String() {CHILD})
DS.Tables(CHILD).PrimaryKey = New DataColumn()
{DS.Tables(CHILD).Columns("ChildID")}
DS.Tables(CHILD).Columns("ChildID").AutoIncrement = True
DS.Tables(CHILD).Columns("ChildID").AutoIncrementSeed = -1
DS.Tables(CHILD).Columns("ChildID").AutoIncrementStep = -1
Return
End Sub
Private Sub BindFields()
uiLabID.DataBindings.Add("Text",
Data.Tables(LabsTable).DefaultView, "LabID")
uiLabName.DataBindings.Add("Text",
Data.Tables(LabsTable).DefaultView, "LabName")
uiStreet.DataBindings.Add("Text",
Data.Tables(LabsTable).DefaultView, "Street")
uiCity.DataBindings.Add("Text",
Data.Tables(LabsTable).DefaultView, "City")
uiState.DataBindings.Add("SelectedValue",
Data.Tables(LabsTable).DefaultView, "State")
uiZip.DataBindings.Add("Text",
Data.Tables(LabsTable).DefaultView, "Zip")
uiProvince.DataBindings.Add("Text",
Data.Tables(LabsTable).DefaultView, "Province")
uiCountry.DataBindings.Add("Text",
Data.Tables(LabsTable).DefaultView, "Country")
Dim PhoneNumberBinding As New Binding("Text",
Data.Tables(LabsTable).DefaultView, "PhoneNumber")
AddHandler PhoneNumberBinding.Format, AddressOf FormatPhone
uiPhoneNumber.DataBindings.Add(PhoneNumberBinding)
Dim FaxNumberBinding As New Binding("Text",
Data.Tables(LabsTable).DefaultView, "FaxNumber")
AddHandler FaxNumberBinding.Format, AddressOf FormatPhone
uiFaxNumber.DataBindings.Add(FaxNumberBinding)
AddHandler
Me.BindingContext(Data.Tables(LabsTable).DefaultView).PositionChanged,
_
AddressOf UpdateStatusForPosition
End Sub
'Handles the Format event for the Phone and Fax numbers
Protected Sub FormatPhone(ByVal sender As Object, ByVal e As
ConvertEventArgs)
If e.Value Is System.DBNull.Value Then
Return
End If
If CStr(e.Value).Length = 10 Then
e.Value = "(" & Strings.Left(e.Value, 3) & ")" & _
Mid(e.Value, 4, 3) & "-" & _
Strings.Right(e.Value, 4)
End If
End Sub
Private Sub frmLab_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Try
Data.Tables(LabsTable).DefaultView.Sort = "LabName ASC"
BindFields()
ChildData.DataSource = Data.Tables(LabsTable)
ChildData.DataMember = "LabsToPVS"
With ChildData
.Cols("PVSID").Visible = False
.Cols("LabID").Visible = False
.Cols("DateEntered").Caption = "Date"
.Cols("StreckOperator").Caption = "Streck Operator"
.Cols("PipetOperator").Caption = "Pipet Operator"
.Cols("LotNumber").Caption = "Lot Number"
.Cols("KitNumber").Caption = "Kit Number"
End With
FirstRecord()
Catch exc As Exception
MessageBox.Show(exc.Message.ToString, "Error Opening Form",
MessageBoxButtons.OK, MessageBoxIcon.Error)
Me.Close()
End Try
End Sub
Private Sub FirstRecord()
Me.BindingContext(Data.Tables(LabsTable).DefaultView).Position
= 0
End Sub
Private Sub UpdateStatusForPosition(ByVal sender As Object, ByVal e As
System.EventArgs)
ShowCurrentRecord()
End Sub
'***** END CODE