Customization Code Help - Specified Cast is not valid

I have a customization for a BAQ Report Form this is causing me issues. I am enabling an disabling the Generate button based on if there is a value (a Pack Slip Number) in the field on the form. If there is a value in the field and I delete it and press tab, I am getting the following error:

Application Error

Exception caught in: BAQReportSOPartSNTag.EP.COMSON.Customization.DisAllowNullPS.CustomCode.28

Error Detail

Message: Specified cast is not valid.
Program: BAQReportSOPartSNTag.EP.COMSON.Customization.DisAllowNullPS.CustomCode.28.dll
Method: BAQReportParam_AfterFieldChange

Client Stack Trace

at Script.BAQReportParam_AfterFieldChange(Object sender, DataColumnChangeEventArgs args)
at System.Data.DataColumnChangeEventHandler.Invoke(Object sender, DataColumnChangeEventArgs e)
at System.Data.DataTable.OnColumnChanged(DataColumnChangeEventArgs e)
at Ice.Rpt.BAQReportDataSet.BAQReportParamDataTable.OnColumnChanged(DataColumnChangeEventArgs e)
at System.Data.DataRow.set_Item(DataColumn column, Object value)
at System.Data.DataRowView.SetColumnValue(DataColumn column, Object value)
at System.Data.DataRowView.set_Item(String property, Object value)
at Ice.Lib.Framework.EpiNumericEditor.TextValidate(Object sender, CancelEventArgs ea)

My code is below. I have tried everything I can think of and cannot get it solved. The Customization compiler does not give me an error or warning, it compiles successfully. I am doing the same thing on another BAQ Report Form with Job Number and I am not having any issues. What am I missing?

private void BAQReportParam_AfterFieldChange(object sender, DataColumnChangeEventArgs args)
	{
		// ** Argument Properties and Uses **
		// args.Row["FieldName"]
		// args.Column, args.ProposedValue, args.Row
		// Add Event Handler Code
		switch (args.Column.ColumnName)
		{
			case "Field1":
			EpiDataView BAQReport = oTrans.Factory("ReportParam");
			
			int PackNum = (int)BAQReport.dataView[BAQReport.Row]["Field1"];

			if (PackNum == 0)
				baseToolbarsManager.Tools["GenerateTool"].SharedProps.Enabled=false;
				
			else
				baseToolbarsManager.Tools["GenerateTool"].SharedProps.Enabled=true;
				break;
		}
	}

Field1 is not likely an integer. Its probably a string?

If you delete the prior packnum from that filed it is now “null”, until the new record is fetched, at which time it will be an empty record whose packnum value defaults to 0.

Add an EndEdit (??) event on that control, and if it is blank, then set it to zero.

The field properties in the customization window state that the NumericType is an Integer. When I created this, I copied and pasted the code from the working Customization with Job Numbers and I received no errors from the compiler but I received the application error “Unable to cast object of type ‘System.Int32’ to type ‘System.String’.”. So I removed all the string casts from that code and replaced them with int. Another block of code was ok with that, but this block is not.

As a test, output the following

EpiMessageBox.Show(BAQReport.dataView[BAQReport.Row]["Field1"].GetType());

Thanks Adam. That helped me.