Textbox filled in by code gets wiped out

I have 2 different forms that are having the same issue. The first is my customization of the Job Entry form. I have added a field that when a part is selected it gets data from a BAQ for the rev from a UD table. I can see via MessageBox the value is being returned and while the message box is open I can see it in the textbox. However, once I dismiss the message box the value is wiped out. In this case I am filling the field in during the AfterFieldChange event like this:

	switch (args.Column.ColumnName)
	{
		case "PartNum":
				string sDraw = edvJobHead.dataView[edvJobHead.Row]["PartNum"].ToString();
				Ice.Lib.Framework.EpiTextBox mytxtDrawRev = (Ice.Lib.Framework.EpiTextBox)csm.GetNativeControlReference("d3d04c9e-8504-445b-8a6f-d5dace5f3e0f");
				Ice.Lib.Framework.EpiTextBox mytxtPartRev = (Ice.Lib.Framework.EpiTextBox)csm.GetNativeControlReference("043ed763-151e-41ef-ad47-8f04f2b0d113");
				DynamicQueryAdapter dqa = new DynamicQueryAdapter(oTrans);
				dqa.BOConnect();
				QueryExecutionDataSet qeds = dqa.GetQueryExecutionParametersByID("DrawingRevLatest2");
				qeds.ExecutionParameter.Clear();
				qeds.ExecutionParameter.AddExecutionParameterRow("PartNum", sDraw , "nvarchar", false, Guid.NewGuid(),"A");
				dqa.ExecuteByID("DrawingRevLatest2",qeds);
				if (dqa.QueryResults.Tables[0].Rows.Count > 0)
				{
					mytxtDrawRev.Text = dqa.QueryResults.Tables[0].Rows[0][2].ToString();
					mytxtPartRev.Text = dqa.QueryResults.Tables[0].Rows[0][5].ToString();	
					MessageBox.Show("have rev " + mytxtDrawRev.Text);
				}
				else
				{
					mytxtDrawRev.Text = "";
					mytxtPartRev.Text = "";	
				}
			break;

I have also tried something similar with the Job Adjustment form where I want to populate the Employee Number with the current user’s Employee ID (from session). I have tried in several events but none of them retain the value. It disappears like the one above. I also have tried updating the employee ID from a BPM but I can’t seem to find the right one. I was trying to set up a BPM off the user clicking the operation complete flag but I don’t get anything (I have put in message boxes to show when it is invoked and I don’t get any message).

Is there a particular event I should or should not be using? I am obviously missing something.

Hi Jeanne,
It’s always best to set the value in the DataView rather than directly to a control’s Text value.

Something like this:

EpiDataView edvPORel = ((EpiDataView)(this.oTrans.EpiDataViews["PORel"]));
System.Data.DataRow edvPORelRow = edvPORel.CurrentDataRow;
if ((edvPORelRow != null))
{
	edvPORelRow.BeginEdit();
	edvPORelRow["ReqNum"] = reqNum;
	edvPORelRow["ReqLine"] = reqLine;
	edvPORelRow.EndEdit();
}

That example is the PORel dataview on a PO Entry customization, yours might be JobHead, JobMtl, etc.

5 Likes

Thanks Andrew. My Job Entry form is now working as desired! However, I tried to implement the same thing in the Job Adjustment form (my customization) and while it fills in the fields it isn’t saving the name or number (or at least I don’t see it when I go back in to look at the record). Am I using the wrong fields or doing something else wrong? It does save the value of the operation complete checkbox.

private void JALaborDtl_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 "OpComplete":
		string currentUser = ((Ice.Core.Session)(((Ice.Lib.Framework.EpiTransaction)oTrans).Session)).EmployeeID;		
		EpiDataView edvLabor = ((EpiDataView)(this.oTrans.EpiDataViews["LaborView"]));
		System.Data.DataRow edvLaborRow=edvLabor.CurrentDataRow;
		if (edvLaborRow != null)
		{
			edvLaborRow.BeginEdit();
			edvLaborRow["EmployeeName"] = ((Ice.Core.Session)(((Ice.Lib.Framework.EpiTransaction)oTrans).Session)).UserName;
			edvLaborRow["EmployeeNum"] = ((Ice.Core.Session)(((Ice.Lib.Framework.EpiTransaction)oTrans).Session)).EmployeeID;
			edvLaborRow.EndEdit();
		}
		break;	
	}
}

Looks OK to me. I’m sure it is applying the values because it won’t let you complete the adjustment without assigning an Employee. I would check Job Tracker and look at the labor transactions to see if the records are there.

It appears that the Job Adjustment form works with a LaborView not the actual Labor Detail table. I tried adding a UD field to store the user name but I don’t see it as an available field for binding a text box to. How can I get my UD field into the view? Are these views updatable? It feels like they should be but I am not seeing any data being saved into the Employee Number (which was already available).