Customization Help - Leave Field Event

Hi all - I've added a field leave event to an existing customization developed by a consultant. The field leave event works as desired when I search for a part on the form the customization is on (Cost Adjustment), but not when I paste the part number in. Any help would be appreciated! I get the following error when pasting the part number: Unhandled Exception - Index -1 is either negative or above rows count.

Here's my field leave event:

Private Sub nedEpiCustom1_Leave(ByVal Sender As Object, ByVal Args As System.EventArgs) Handles nedEpiCustom1.Leave
'// ** Place Event Handling Code Here **

Dim edvPartMaster As EpiDataView = CType(oTrans.EpiDataViews("PartMaster"), EpiDataView)
Dim varMtlBurRate As Decimal = edvPartMaster.dataView(edvPartMaster.Row)("MtlBurRate")

nedEpiCustom5.Value = varMtlBurRate/100 * nedEpiCustom1.value

End Sub




Here's all of the custom code on the cost adjustment form:


'//**************************************************
'// Custom VB.NET code for CostAdjustmentForm
'// Created: 11/9/2010 3:46:21 PM
'//**************************************************
Imports System
Imports System.Data
Imports System.Diagnostics
Imports System.Windows.Forms
Imports System.ComponentModel
Imports Microsoft.VisualBasic
Imports Epicor.Mfg.UI
Imports Epicor.Mfg.UI.FrameWork
Imports Epicor.Mfg.UI.ExtendedProps
Imports Epicor.Mfg.UI.FormFunctions
Imports Epicor.Mfg.UI.Customization
Imports Epicor.Mfg.UI.Adapters
Imports Epicor.Mfg.UI.Searches
Imports Epicor.Mfg.BO
Imports System.reflection
Imports System.Collections.Generic

Module Script


'// ** Wizard Insert Location - Do Not Remove 'Begin/End Wizard Added Module Level Variables' Comments! **
'// Begin Wizard Added Module Level Variables **

Private WithEvents oTrans_costAdapter As EpiBaseAdapter
Private WithEvents edvPart As EpiDataView
Dim Toolbar as Infragistics.Win.UltraWinToolbars.UltraToolbarsManager
Dim partAdapter AS Epicor.Mfg.UI.Adapters.partAdapter
Dim partCostSearchAdapter AS Epicor.Mfg.UI.Adapters.partCostSearchAdapter
Dim tmpPartCostDT As DataTable

Private WithEvents oTrans_partAdapter As EpiBaseAdapter

Private WithEvents edvCost As EpiDataView
'// End Wizard Added Module Level Variables **


'// Add Custom Module Level Variables Here **



Sub InitializeCustomCode()


'// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Intialization' lines **
'// Begin Wizard Added Variable Intialization

oTrans_costAdapter = csm.TransAdaptersHT("oTrans_costAdapter")
edvPart = CType(oTrans.EpiDataViews("Part"), EpiDataView)

partAdapter = new partAdapter(oTrans)
partAdapter.BOConnect()

partCostSearchAdapter = new partCostSearchAdapter(oTrans)
partCostSearchAdapter.BOConnect()

Dim obj as Object = GetType(Epicor.Mfg.UI.App.CostAdjustmentEntry.CostAdjustmentForm).InvokeMember("baseToolbarsManager", BindingFlags.Instance Or BindingFlags.GetField Or BindingFlags.NonPublic, Nothing, CostAdjustmentForm, Nothing)
Toolbar = ctype(obj,Infragistics.Win.UltraWinToolbars.UltraToolbarsManager)

'AddHandler Toolbar.Tools("Savetool").ToolClick, AddressOf CostAdjustmentForm_CustomToolClick

addhandler Toolbar.ToolClick, addressof buttonClick

oTrans_partAdapter = csm.TransAdaptersHT("oTrans_partAdapter")
edvPart = CType(oTrans.EpiDataViews("Part"), EpiDataView)
edvCost = CType(oTrans.EpiDataViews("Cost"), EpiDataView)
'// End Wizard Added Variable Intialization
'// Begin Custom Method Calls

'// End Custom Method Calls
End Sub



Sub DestroyCustomCode()


'// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
'// Begin Wizard Added Object Disposal

oTrans_costAdapter = Nothing
edvPart = Nothing
oTrans_partAdapter = Nothing
edvCost = Nothing
'// End Wizard Added Object Disposal
'// Begin Custom Code Disposal

'// End Custom Code Disposal
End Sub

Private Sub buttonClick(sender As Object, e As Infragistics.Win.UltraWinToolbars.ToolClickEventArgs)
Select Case (e.Tool.key)
case "SaveTool"
SaveCosts()

case "DeleteTool"

case "ClearTool"
defaultValues()

case "RefreshTool"
'assignValues()

End Select
End Sub

Sub SaveCosts()
if Cost_Row.Dataview.count > 0 then
dim opt as SearchOptions = new SearchOptions(SearchMode.AutoSearch)
opt.DataSetMode = DataSetMode.RowsDataSet
opt.PreLoadSearchFilter = "PartNum = '"+ Cost_Row.dataView(Cost_Row.Row)("PartNum").tostring() +"' "
partCostSearchAdapter.InvokeSearch(opt)

if(partCostSearchAdapter.partCostSearchData.PartCost.Rows.Count > 0)
partCostSearchAdapter.partCostSearchData.PartCost(0)("Number01") = nedEpiCustom1.Value
partCostSearchAdapter.partCostSearchData.PartCost(0)("Number02") = nedEpiCustom2.Value
partCostSearchAdapter.partCostSearchData.PartCost(0)("Number03") = nedEpiCustom3.Value
partCostSearchAdapter.partCostSearchData.PartCost(0)("Number04") = nedEpiCustom4.Value
partCostSearchAdapter.partCostSearchData.PartCost(0)("Number05") = nedEpiCustom5.Value
partCostSearchAdapter.partCostSearchData.PartCost(0)("Number06") = nedEpiCustom7.Value
partCostSearchAdapter.partCostSearchData.PartCost(0)("Number07") = nedEpiCustom8.Value
partCostSearchAdapter.partCostSearchData.PartCost(0)("Number08") = nedEpiCustom9.Value
partCostSearchAdapter.partCostSearchData.PartCost(0)("Number09") = nedEpiCustom10.Value
partCostSearchAdapter.partCostSearchData.PartCost(0)("Number10") = nedEpiCustom11.Value
partCostSearchAdapter.update()

nedEpiCustom6.Value = nedEpiCustom1.Value + nedEpiCustom2.Value + nedEpiCustom3.Value + nedEpiCustom4.Value + nedEpiCustom5.Value
nedEpiCustom12.Value = nedEpiCustom7.Value + nedEpiCustom8.Value + nedEpiCustom9.Value + nedEpiCustom10.Value + nedEpiCustom11.Value
end if

end if
end sub

Public Class CR8DynamicQuery
Public Shared Function GetDynamicQueryResults(ByVal argBAQName As String, ByVal argWhereClauseList As List(Of CR8DynamicQueryWhereClause), ByVal argTransaction As EpiTransaction) As DataTable
Dim tmpDQA As DynamicQueryAdapter = New DynamicQueryAdapter(argTransaction)
tmpDQA.BOConnect()
tmpDQA.GetDashboardQuery(argBAQName)
Dim tmpQueryDT As DataTable = tmpDQA.RunTimeQuery.Tables("QueryTable")
For Each tmpWhereClause As CR8DynamicQueryWhereClause In argWhereClauseList
For Each tmpQueryDR As DataRow In tmpQueryDT.Rows
If tmpQueryDR("DataTableName").ToString() <> tmpWhereClause.TableName Then
tmpQueryDR("WhereClause") = tmpWhereClause.WhereClause
Exit For
End If
Next
Next
tmpDQA.ExecuteDashboardQuery(tmpDQA.RunTimeQuery)
Dim tmpResultsDT as Datatable = tmpDQA.QueryResults.Tables("Results")
tmpDQA.Dispose()
Return tmpResultsDT
End Function
End Class

Public Class CR8DynamicQueryWhereClause
Private _TableName As String = ""
Private _WhereClause As String = ""

Public Property TableName() As String
Get
Return _TableName
End Get
Set(ByVal value As String)
_TableName = value
End Set
End Property

Public Property WhereClause() As String
Get
Return _WhereClause
End Get
Set(ByVal value As String)
_WhereClause = value
End Set
End Property

Public Sub New(ByVal argTableName As String, ByVal argWhereClause As String)
TableName = argTableName
WhereClause = argWhereClause
End Sub
End Class

Sub assignValues()
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor
Dim tmpCustomerWhereClause As String = String.Empty

'build the where clause
tmpCustomerWhereClause = "PartCost.PartNum = '" + Cost_Row.Dataview(Cost_Row.Row)("PartNum").tostring + "' "

Dim tmpWhereClauseList As List(Of CR8DynamicQueryWhereClause)= new List(Of CR8DynamicQueryWhereClause)

If tmpCustomerWhereClause <> String.Empty Then
tmpWhereClauseList.Add(new CR8DynamicQueryWhereClause("Customer",tmpCustomerWhereClause))
End If

tmpPartCostDT =CR8DynamicQuery.GetDynamicQueryResults("STI-PartCost_Adjustment",tmpWhereClauseList,oTrans)

'nedEpiCustom1.Value = Convert.ToInt32(tmpPartCostDT.Rows(0)("PartCost.Number01"))
nedEpiCustom1.Value = tmpPartCostDT.Rows(0)("PartCost.Number01")
nedEpiCustom2.Value = tmpPartCostDT.Rows(0)("PartCost.Number02")
nedEpiCustom3.Value = tmpPartCostDT.Rows(0)("PartCost.Number03")
nedEpiCustom4.Value = tmpPartCostDT.Rows(0)("PartCost.Number04")
nedEpiCustom5.Value = tmpPartCostDT.Rows(0)("PartCost.Number05")
nedEpiCustom7.Value = tmpPartCostDT.Rows(0)("PartCost.Number06")
nedEpiCustom8.Value = tmpPartCostDT.Rows(0)("PartCost.Number07")
nedEpiCustom9.Value = tmpPartCostDT.Rows(0)("PartCost.Number08")
nedEpiCustom10.Value = tmpPartCostDT.Rows(0)("PartCost.Number09")
nedEpiCustom11.Value = tmpPartCostDT.Rows(0)("PartCost.Number10")

nedEpiCustom6.Value = nedEpiCustom1.Value + nedEpiCustom2.Value + nedEpiCustom3.Value + nedEpiCustom4.Value + nedEpiCustom5.Value
nedEpiCustom12.Value = nedEpiCustom7.Value + nedEpiCustom8.Value + nedEpiCustom9.Value + nedEpiCustom10.Value + nedEpiCustom11.Value
End Sub

Private Sub CostAdjustmentForm_Load(ByVal sender As object, ByVal args As EventArgs) Handles CostAdjustmentForm.Load
'//
'// Add Event Handler Code
'//
defaultValues()
End Sub

Sub defaultValues()
nedEpiCustom1.Value = 0.00000
nedEpiCustom2.Value = 0.00000
nedEpiCustom3.Value = 0.00000
nedEpiCustom4.Value = 0.00000
nedEpiCustom5.Value = 0.00000
nedEpiCustom6.Value = 0.00000
nedEpiCustom7.Value = 0.00000
nedEpiCustom8.Value = 0.00000
nedEpiCustom9.Value = 0.00000
nedEpiCustom10.Value = 0.00000
nedEpiCustom11.Value = 0.00000
nedEpiCustom12.Value = 0.00000
end Sub

Dim part as string
Private Sub edvCost_EpiViewNotification(view As EpiDataView, args As EpiNotifyArgs) Handles edvCost.EpiViewNotification
'// ** Argument Properties and Uses **
'// view.dataView(args.Row)("[FieldName]")
'// args.Row, args.Column, args.Sender, args.NotifyType
'// NotifyType.Initialize, NotifyType.AddRow, NotifyType.DeleteRow, NotifyType.InitLastView, NotifyType.InitAndResetTreeNodes

if Cost_Row.Dataview.Count > 0 then
'if part <> Cost_Row.Dataview(Cost_Row.Row)("PartNum").tostring then
assignValues()
'part = Cost_Row.Dataview(Cost_Row.Row)("PartNum").tostring
'end if
end if
End Sub







Private Sub nedEpiCustom1_Leave(ByVal Sender As Object, ByVal Args As System.EventArgs) Handles nedEpiCustom1.Leave
'// ** Place Event Handling Code Here **
Dim edvPartMaster As EpiDataView = CType(oTrans.EpiDataViews("PartMaster"), EpiDataView)
Dim varMtlBurRate As Decimal = edvPartMaster.dataView(edvPartMaster.Row)("MtlBurRate")
nedEpiCustom5.Value = varMtlBurRate/100 * nedEpiCustom1.value

End Sub


Private Sub nedEpiCustom7_Leave(ByVal Sender As Object, ByVal Args As System.EventArgs) Handles nedEpiCustom7.Leave
'// ** Place Event Handling Code Here **
Dim edvPartMaster As EpiDataView = CType(oTrans.EpiDataViews("PartMaster"), EpiDataView)
Dim varMtlBurRate As Decimal = edvPartMaster.dataView(edvPartMaster.Row)("MtlBurRate")
nedEpiCustom11.Value = varMtlBurRate/100 * nedEpiCustom7.value
End Sub


End Module