Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AddNew databinding problem

Status
Not open for further replies.

Kenny62

Programmer
Mar 3, 2004
54
GB
Addnew databinding problem:
Hi - i have databinding problem, i wonder if someonecan help:

Briefly, i have table with the following fields
ID (identity, not NULL)
ClientID (integer, not NULL)
ProgramID (integer, not NULL)
StartDate (datedtime, not NULL)
EndDate (datetime, nullable)

Databind is as follows: Data binding is setup via the SetBindings sub,
AddNew is called in the btnNew_Click event handler: Assuming a empty dataset the debug statements output:
'0' before Addnew is called and '1' after.
The btnOK_Click event handler ends the current edits and calls Me.Changed. On examining the table.rows.count property
i find it is zero: i.e no new rows. Therfore table.getchanges is nothing. Any idea why? How do i get
this AddNew to work. Thanks for any help in advance.

Private _bmb As BindingManagerBase

Sub SetBindings(ByVal DS As DataSet)
lblCID.DataBindings.Clear()
_C1StartDT.DataBindings.Clear()
_C1EndDT.DataBindings.Clear()
cboProgram.DataBindings.Clear()

Try
lblCID.DataBindings.Add("Text", DS.Tables("ClientProgram").DefaultView, "ClientID")

_dataSet.Tables("ClientProgram").Columns("ProgramID").DefaultValue = System.Convert.DBNull
cboProgram.DataBindings.Add("SelectedValue", DS.Tables("ClientProgram").DefaultView, "ProgramID")

_C1StartDT.DataBindings.Add("Value", DS.Tables("ClientProgram").DefaultView, "StartDate")
_C1EndDT.DataBindings.Add("Value", DS.Tables("ClientProgram").DefaultView, "EndDate")

_bmb = Me.BindingContext(DS.Tables("ClientProgram").DefaultView)
Catch ex As Exception
ErrHandler.HandleException(Me, ex)
End Try
End Sub


Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click
Dim ThisPID As Integer
Dim ThisRow As Integer

ThisPID = CInt(cboProgram.SelectedValue)
Debug.WriteLine("Before add Cnt:" & CStr(_bmb.Count()))
_bmb.AddNew()
Debug.WriteLine("After add Cnt:" & CStr(_bmb.Count()))
'Reset CID, PID...
lblCID.Text = CStr(m_ThisClient)
cboProgram.SelectedValue = ThisPID
'ThisRow = _dataSet.Tables("ClientProgram").Rows.Count
'_dataGrid.Item(_dataGrid.CurrentRowIndex(), 1) = m_ThisClient
'_dataGrid.Item(_dataGrid.CurrentRowIndex(), 2) = ThisPID

End Sub

Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click

Try
BindingContext(_dataSet, "ClientProgram").EndCurrentEdit())
Catch ex As Exception
ErrHandler.HandleException(Me, ex)
End Try

If Me.Changed Then
Try
'db.ClientProgramCollection.Update(_dataSet.Tables("ClientProgram"))
Catch ex As Exception
ErrHandler.HandleException(Me, ex)
End Try
End If


End Sub

Protected Overrides ReadOnly Property Changed() As Boolean
Get
Dim table As DataTable = _dataSet.Tables("ClientProgram")
Debug.WriteLine("Changed add Cnt:" & CStr(_bmb.Count()))
If Not (table Is Nothing) Then
Return Not (table.GetChanges() Is Nothing)
End If
Return False
End Get
End Property
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top