Adding new dropshipment lines is not initializing grid

We have added a formula column into the dropship grid and a field that totals this new column to the form.

 

This code is run under a Grid_InitializeRow handle.

 

The issue we are facing is that when a drop ship line is added, it does not seem to hit this handle so our fields are blank. If a row is deleted, or the user exits and re-enters the form then the fields are populated correctly. Does anyone know why when either adding a mass shipment/ get all or adding a single line this code is not firing? Following is the code we currently have

' **************************************************
' Custom code for DropShipForm
' Created: 6/13/2013 9:21:31 AM
' Author: Daniel Milano
' Receipt/ship date clears out before update
' Saves DropShipHead.ReceiptDate date and inserts before update
' Zero cost error message done by Bob G.
' Daniel Milano - Aug 19 2013:
' Add Tracking number
' UD field for weight
' UD field for unit of measure
' Button to view URL for tracking 
' DEV 179 - August 28 2013
' Drop Ship Lines
' DEV221 - October 14 2013
' Future ship date warning -- asks user if current ship date should be used if ship date is in future.
' **************************************************
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Diagnostics
Imports System.Windows.Forms
Imports Microsoft.VisualBasic
Imports Epicor.Mfg.BO
Imports Epicor.Mfg.UI
Imports Epicor.Mfg.UI.Adapters
Imports Epicor.Mfg.UI.Customization
Imports Epicor.Mfg.UI.ExtendedProps
Imports Epicor.Mfg.UI.FormFunctions
Imports Epicor.Mfg.UI.FrameWork
Imports Epicor.Mfg.UI.Searches
Imports Infragistics.Win.UltraWinGrid '//DEV179 Daniel Milano

Public Class Script

 ' ** Wizard Insert Location - Do Not Remove 'Begin/End Wizard Added Module Level Variables' Comments! **
 ' Begin Wizard Added Module Level Variables **
 private tempDate as Date
 private totalvendorcost as double
 private totalourcost as double
 private i as integer
 private ponumber as integer

 Private WithEvents oTrans_adapter As EpiBaseAdapter
 private uomclass as UOMClassAdapter
 dim WithEvents ReceiptsGrid  As EpiUltraGrid

 Private WithEvents edvMultiKeySearch As EpiDataView
 Private WithEvents MultiKeySearch_DataView As DataView
 Private WithEvents DropShipDtl_DataView As DataView
 ' End Wizard Added Module Level Variables **

 ' Add Custom Module Level Variables Here **

 Public Sub InitializeCustomCode()
  ' ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
  ' Begin Wizard Added Variable Initialization

  AddHandler Me.DropShipHead_Column.ColumnChanged, AddressOf Me.DropShipHead_AfterFieldChange

  tempDate = now()
  totalvendorcost = 0
  totalourcost = 0
  i = 0
  ponumber = 0

  Me.oTrans_adapter = CType(Me.csm.TransAdaptersHT("oTrans_adapter"),EpiBaseAdapter)
  AddHandler Me.oTrans_adapter.AfterAdapterMethod, AddressOf Me.oTrans_adapter_AfterAdapterMethod
  AddHandler Me.oTrans_adapter.BeforeAdapterMethod, AddressOf Me.oTrans_adapter_BeforeAdapterMethod
  AddHandler Me.DropShipHead_Column.ColumnChanging, AddressOf Me.DropShipHead_BeforeFieldChange
  Me.edvMultiKeySearch = CType(Me.oTrans.EpiDataViews("MultiKeySearch"),EpiDataView)
  Me.MultiKeySearch_DataView = Me.MultiKeySearch_Row.dataView
  AddHandler Me.MultiKeySearch_DataView.ListChanged, AddressOf Me.MultiKeySearch_DataView_ListChanged
  Me.DropShipDtl_DataView = Me.DropShipDtl_Row.dataView
  AddHandler Me.DropShipDtl_Row.EpiRowChanged, AddressOf Me.DropShipDtl_AfterRowChange
  ' End Wizard Added Variable Initialization

  ' Begin Wizard Added Custom Method Calls

  AddHandler Me.UOMList.Click, AddressOf Me.UOMList_Click
  AddHandler Me.btnURL.Click, AddressOf Me.btnURL_Click
  ' End Wizard Added Custom Method Calls

  ReceiptsGrid  = ctype(csm.GetNativeControlReference("87f88dc8-1b94-4324-ba83-583a2af5cbb9"), Epicor.Mfg.UI.FrameWork.EpiUltraGrid)
  ReceiptsGrid.DisplayLayout.Bands(0).Columns.Add("SupplierExtCost", "Supplier Cost")
  ReceiptsGrid.DisplayLayout.Bands(0).Columns.Add("OurExtCost", "Our Cost")
  ReceiptsGrid.DisplayLayout.Bands(0).Columns("SupplierExtCost").Header.VisiblePosition = 24
  ReceiptsGrid.DisplayLayout.Bands(0).Columns("SupplierExtCost").CellAppearance.TextHAlign = Infragistics.Win.HAlign.Right
  ReceiptsGrid.DisplayLayout.Bands(0).Columns("OurExtCost").CellAppearance.TextHAlign = Infragistics.Win.HAlign.Right
'  AddHandler ReceiptsGrid.AfterRowUpdate , AddressOf ReceiptsGrid_AfterRowUpdate
  AddHandler ReceiptsGrid.InitializeRow , AddressOf ReceiptsGrid_InitializeRow

 End Sub

 Public Sub DestroyCustomCode()
  ' ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
  ' Begin Wizard Added Object Disposal

  RemoveHandler Me.DropShipHead_Column.ColumnChanged, AddressOf Me.DropShipHead_AfterFieldChange
  RemoveHandler Me.oTrans_adapter.AfterAdapterMethod, AddressOf Me.oTrans_adapter_AfterAdapterMethod
  Me.oTrans_adapter = Nothing
  RemoveHandler Me.oTrans_adapter.BeforeAdapterMethod, AddressOf Me.oTrans_adapter_BeforeAdapterMethod
  RemoveHandler Me.UOMList.Click, AddressOf Me.UOMList_Click
  RemoveHandler Me.btnURL.Click, AddressOf Me.btnURL_Click
  RemoveHandler Me.DropShipHead_Column.ColumnChanging, AddressOf Me.DropShipHead_BeforeFieldChange
  RemoveHandler ReceiptsGrid.InitializeRow , AddressOf ReceiptsGrid_InitializeRow
'  RemoveHandler ReceiptsGrid.AfterRowUpdate , AddressOf ReceiptsGrid_AfterRowUpdate
  Me.edvMultiKeySearch = Nothing
  RemoveHandler Me.MultiKeySearch_DataView.ListChanged, AddressOf Me.MultiKeySearch_DataView_ListChanged
  Me.MultiKeySearch_DataView = Nothing
  Me.DropShipDtl_DataView = Nothing
  RemoveHandler Me.DropShipDtl_Row.EpiRowChanged, AddressOf Me.DropShipDtl_AfterRowChange
  ' End Wizard Added Object Disposal

  ' Begin Custom Code Disposal
  tempDate = nothing

  ' End Custom Code Disposal
 End Sub

 Private Sub DropShipHead_AfterFieldChange(ByVal sender As Object, ByVal args As DataColumnChangeEventArgs)
  ' ** Argument Properties and Uses **
  ' args.Row("FieldName")
  ' args.Column, args.ProposedValue, args.Row
  ' Add Event Handler Code
  Select Case args.Column.ColumnName
   Case "ReceiptDate"
    Dim HeaderView As EpiDataView = CType(oTrans.EpiDataViews("DropShipHead"), EpiDataView)
    if(not isdbnull(HeaderView.dataView(HeaderView.Row)("ReceiptDate")) and not isdbnull(tempDate))then
     tempDate = HeaderView.dataView(HeaderView.Row)("ReceiptDate")
    end if
    HeaderView = nothing
  End Select
 End Sub

 private sub ReceiptsGrid_InitializeRow(ByVal sender as object, ByVal e As Infragistics.Win.UltraWinGrid.InitializeRowEventArgs)Handles ReceiptsGrid.InitializeRow
  try

   if(i = 0 or e.Row.Index = i)then
    if(e.Row.Index = 0)then
     curTotalSupplierExtCost.Value = 0
     totalvendorcost = 0
     totalourcost = 0
    end if
     
    Dim suppliercost As Decimal = 0
    Dim ourcost As Decimal = 0
    suppliercost = double.parse(e.Row.Cells("VendorQty").Value) * double.parse(e.Row.Cells("VendorUnitCost").Value)
    ourcost = double.parse(e.Row.Cells("OurQty").Value) * double.parse(e.Row.Cells("OurUnitCost").Value)
    
    e.Row.Cells("SupplierExtCost").Value = suppliercost.ToString("F")
    e.Row.Cells("OurExtCost").Value = ourcost.ToString("F")
  
    totalvendorcost +=  suppliercost
    totalourcost += ourcost
 
    curTotalSupplierExtCost.Value = totalvendorcost
    i += 1
 
   end if

  catch ex as exception
   messagebox.show(ex.message)
  end try

 end sub

 Private Sub oTrans_adapter_AfterAdapterMethod(ByVal sender As Object, ByVal args As AfterAdapterMethodArgs)
  ' ** Argument Properties and Uses **
  ' ** args.MethodName **
  ' ** Add Event Handler Code **
 
  ' ** Use MessageBox to find adapter method name
  ' EpiMessageBox.Show(args.MethodName)
  Select Case args.MethodName
 
   Case "Update"
    Dim HeaderView As EpiDataView = CType(oTrans.EpiDataViews("DropShipHead"), EpiDataView)
    HeaderView.dataView(HeaderView.Row)("ReceiptDate") = tempDate
    Dim e As Infragistics.Win.UltraWinGrid.InitializeRowEventArgs    
    HeaderView = nothing
    
  End Select
  
 
 End Sub

 Private Sub oTrans_adapter_BeforeAdapterMethod(ByVal sender As Object, ByVal args As BeforeAdapterMethodArgs)
 'Added by Bob G.
  ' ** Argument Properties and Uses **
  ' ** args.MethodName **
  ' ** Add Event Handler Code **
 
  ' ** Use MessageBox to find adapter method name
  ' EpiMessageBox.Show(args.MethodName)
  Select Case args.MethodName
 
   Case "Update"
     Dim DetailView As EpiDataView = CType(oTrans.EpiDataViews("DropShipDtl"), EpiDataView)
                 Dim ErrMsg as string
                 for each row as datarow in DetailView.dataView.Table.Rows
                   if row("OurUnitCost") = 0 then
                     ErrMsg = ErrMsg & Environment.NewLine & row("PartNum")& " has Zero cost"
                   End if
                 next
                 If ErrMsg <> "" then
       Dim dialogResult As DialogResult = EpiMessageBox.Show(ErrMsg, "Cancel", MessageBoxButtons.YesNo)
       If (dialogResult = DialogResult.Yes) Then
      args.Cancel = true
       End If
                 End If 
  End Select
 
 End Sub

 Private Sub UOMList_Click(ByVal sender As Object, ByVal args As System.EventArgs)
  ' ** Place Event Handling Code Here **
  uomclass = new UOMClassAdapter(oTrans)
  uomclass.BOConnect()

  Dim dsUOMClassAdapter As System.Data.DataSet = uomclass.Getdata("weight")
  dim table as datatable
  dim row as datarow
  dim column as datacolumn

  dim uomlists as new ArrayList()
  for each row in dsUOMClassAdapter.tables(1).rows
   uomlists.add(row(2))    
  next row
  
  'Set EpiUltraCombo Properties
  Me.UOMList.datasource = uomlists
 
 End Sub

 Private Sub btnURL_Click(ByVal sender As Object, ByVal args As System.EventArgs)

  Dim tracking As EpiDataView = CType(oTrans.EpiDataViews("DropShipHead"), EpiDataView)
  dim shipviacode = ""
  shipviacode = tracking.dataView(tracking.Row)("ShipViaCode") 
  
  dim trackingURL as string
  dim placeURL as string
  dim trackingnumber as string

  trackingURL = ""
  placeURL = ""
  trackingnumber = ""
   
  Dim recSelected As Boolean
  Dim whereClause As String = "shipviacode = '" & shipviacode & "'"
  Dim ds As System.Data.DataSet = Epicor.Mfg.UI.FormFunctions.SearchFunctions.listLookup(Me.oTrans, "ShipViaAdapter", recSelected, false, whereClause)

  If recSelected Then
   trackingURL = ds.tables(0).rows(0)(5)
   placeURL = ds.tables(0).rows(0)(6)
  End If

  recSelected = nothing
  whereClause = nothing
  ds = nothing

  '//tracking number provided by carrier
  trackingnumber = tracking.dataView(tracking.Row)("TrackingNumber")  

  '//error checking
  
  if(shipviacode = "")then
   messagebox.show("Ship Via is Blank.", "Error", MessageboxButtons.OK, MessageBoxIcon.Exclamation)
   tracking = nothing
   exit sub
  end if


  if(trackingURL = "")then
   messagebox.show("No Tracking URL found on the ShipVia setup.", "Error", MessageboxButtons.OK, MessageBoxIcon.Exclamation)
   tracking = nothing
   exit sub
  elseif(trackingnumber = "")then
   messagebox.show("Tracking number has not been provided.", "Error", MessageboxButtons.OK, MessageBoxIcon.Exclamation)
   tracking = nothing
   exit sub
  else
   '//creates actual tracking url by replaceing the place holder
   trackingURL = trackingURL.replace(placeURL, trackingnumber)
   process.start("iexplore.exe", trackingurl)
   
  end if

  tracking = nothing

 end sub
 Private Sub DropShipHead_BeforeFieldChange(ByVal sender As Object, ByVal args As DataColumnChangeEventArgs)
  ' ** Argument Properties and Uses **
  ' args.Row("FieldName")
  ' args.Column, args.ProposedValue, args.Row
  ' Add Event Handler Code
  Select Case args.Column.ColumnName

   Case "ReceiptDate"

    Try
     If Convert.ToDateTime(args.ProposedValue) < DateTime.Today Then
      Dim result As DialogResult = MessageBox.Show("Ship date occurs prior to today's date. Do you want to change the ship date to today's date?", "Future Ship Date", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation)
      If result = DialogResult.Yes Then
       args.ProposedValue = DateTime.Today
      End If
     End If
    Catch e As Exception
    End Try
  End Select
 End Sub

 Private Sub MultiKeySearch_DataView_ListChanged(ByVal sender As Object, ByVal args As ListChangedEventArgs)
  ' ** Argument Properties and Uses **
  ' MultiKeySearch_DataView(0)("FieldName")
  ' args.ListChangedType, args.NewIndex, args.OldIndex
  ' ListChangedType.ItemAdded, ListChangedType.ItemChanged, ListChangedType.ItemDeleted, ListChangedType.ItemMoved, ListChangedType.Reset
  ' Add Event Handler Code

   if(integer.parse(MultiKeySearch_DataView(0)("ponum")) = 0 or integer.parse(MultiKeySearch_DataView(0)("ponum")) <> ponumber)then
    ponumber = integer.parse(MultiKeySearch_DataView(0)("ponum"))
    i = 0
    curTotalSupplierExtCost.Value = 0
   end if

 End Sub

 

 Private Sub DropShipDtl_AfterRowChange(ByVal args As EpiRowChangedArgs)
  ' ** Argument Properties and Uses **
  ' args.CurrentView.dataView(args.CurrentRow)("FieldName")
  ' args.LastRow, args.CurrentRow, args.CurrentView
  ' Add Event Handler Code
  
  
 End Sub
End Class