Home All Groups Group Topic Archive Search About

Adding new Strongly typed Row - BindingSource Errors

Author
8 Jul 2006 12:46 PM
ECathell
I am trying to add a new item to a table based on another item in the same table. To do this I have the user click on the + button on the navigator. A form is displayed where they enter the new primary key information, tell it what type of templated Item to use and then press ok. In the real world it is adding the row correctly to the database, however I keep getting binding source errors whether it is positional errors(no row at position 837) or invalid object errors(you can only add the same item type to a binding list)

depending on how I try rearanging my code it varies the error. Below is the current itteration of my code. I have also had the bindingsource_addnew function too ...

Hope this is somewhat clear.....



Private Sub ProductsBindingNavigatorAddNewItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProductsBindingNavigatorAddNewItem.Click
  Try
   fillProductInformation()
   Me.ProductsBindingsource.MoveLast()
  Catch ex As Exception

  End Try
End Sub



Fill Product information:
Private Sub fillProductInformation()
  Try
   Me.Product = getProductData()

   If Not IsNothing(Product) Then
    Me.Products.AddProductsRow(Product)
    Me.ProductsTableAdapter.Update(Products)
   End If
  Catch ex As Exception

  End Try

End Sub


GetProductData:
Private Function getProductData() As dsInvmgmtDataSet.ProductsRow
  Dim frm As New NewProductEntryForm
  Dim dlg As New DialogResult

  Try
   frm.ShowDialog()
   frm.Owner = Me
   dlg = frm.DialogResult

   If dlg = Windows.Forms.DialogResult.Cancel Then
    Return Nothing
   End If
   If frm.UseTemplate = True Then
    Product = getTemplateData(frm.TemplateProductCode)
   End If

   If frm.UseTemplate = False Then
    Product = getDefaultData(frm.NewProductCode, frm.PrePackCheckBox.Checked)
   End If
  Catch ex As Exception

  End Try
  Return Product

End Function

Private Function getTemplateData(ByVal pluno As Integer) As dsInvmgmtDataSet.ProductsRow
  Dim NewDataRow As dsInvmgmtDataSet.ProductsRow = Products.NewProductsRow
  Dim Template As dsInvmgmtDataSet.ProductsRow


  Template = Me.Products.FindByPLUNo(pluno)
  NewDataRow = Template

  With NewDataRow
   .PLUNo = pluno
   .ProdCode = pluno
   .ItemNo = pluno
   .CustNo = 1
  End With

  Return NewDataRow

End Function

Private Function getDefaultData(ByVal pluno As Integer, ByVal isPrePack As Boolean) As dsInvmgmtDataSet.ProductsRow
  Dim NewDataRow As dsInvmgmtDataSet.ProductsRow = Products.NewProductsRow
  Dim Template As dsInvmgmtDataSet.ProductsRow


  Try
   If isPrePack = True Then
    Template = Products.FindByPLUNo(My.Settings.TrayPackDefaultProduct)
   Else
    Template = Products.FindByPLUNo(My.Settings.IcePackDefaultProduct)
   End If
   NewDataRow.ItemArray = Template.ItemArray.Clone
   With NewDataRow
    .PLUNo = pluno
    .ProdCode = pluno
    .ItemNo = pluno
    .CustNo = 1
   End With
  Catch ex As Exception

  End Try


  Return NewDataRow


End Function


--
--Eric Cathell, MCSA

AddThis Social Bookmark Button