How to retain feild change after the message box pop up in C#(Epicor, ERP)?

I am extremely new to C# and Epicor. The referred to code starts from case "CountryofOrigin_c"

The code referred to starts from - case “CountryofOrigin_c”:

I have a field called Country of Origin(COO) that has a drop list of the countries. If the user types in an invalid country I want the field to go blank. The user input of the country is captured by (cmbCountryOrg.Text).

Now, the cmbCountryOrg.Text=""; works temporarily but only if the message box is displayed after it. The field reverts back to the user input country after clicking OK on the message box. Secondly, it does not work if the message box was displayed before it. Thirdly, it doesn’t work at all without the message box.


private void OrderDtl_AfterFieldChange(object sender, DataColumnChangeEventArgs args)
	{
         MessageBox.Show("Testing AfterFieldChange");
		switch (args.Column.ColumnName)
		{
			case "PartNum":if(!string.IsNullOrEmpty(Convert.ToString(args.Row["PartNum"])))
							{
								/*args.Row["HTSCode_c"]= string.Empty;
								args.Row["CountryofOrigin_c"] =string.Empty;
								txtHTSCodeDesc.Text = "";
	*/
								DataTable dt =GetBAQ("EL_PartData");
								string RowFilter = "Part_PartNum ='" + Convert.ToString(args.Row["PartNum"]) + "'";
								DataTable dtFilter = Filter(dt,RowFilter);
								if(dtFilter.Rows.Count > 0)
								{
									args.Row.BeginEdit();
									args.Row["HTSCode_c"]= dtFilter.Rows[0]["Part_CommodityCode"];
									args.Row["CountryofOrigin_c"] =dtFilter.Rows[0]["Part_ISOrigCountry"];
									args.Row.EndEdit();
								}
							}
							else
							{
								args.Row["HTSCode_c"]= string.Empty;
								args.Row["CountryofOrigin_c"] =string.Empty;
								txtHTSCodeDesc.Text = "";
							}
				break;

			case "CountryofOrigin_c": DataTable dt1 = GetBAQ("NML_COOList");
	    	string RowFilter1 = "Country_Description ='" + Convert.ToString(cmbCountryOrg.Text) + "'";
			MessageBox.Show("RowFltr",RowFilter1);
			DataTable dtFilter1 = Filter(dt1,RowFilter1);
			if (dtFilter1.Rows.Count==0)
			{
	   		MessageBox.Show("cmbCountryOrg.Text",cmbCountryOrg.Text);
			   cmbCountryOrg.Text="";
			   string message = "Enter a valid country name.";
			   MessageBox.Show(message);
			
 
			}
				break;
		}
	}

Better to restrict the typing in the combo box and only selection from the list.

this.comboBoxType.DropDownStyle = ComboBoxStyle.DropDownList;
1 Like

Thanks @fakhruddin for your reply. The funny thing is that it was previously written the way you have suggested. We wanted to add the functionality where users could type in the country name and it populates the name as you type.

@HargulS I think you would want to use BeforeFieldChange and test if the args,ProposedValue is valid. If not then set the proposedValue back to the current value.

@gpayne Thanks a ton! I used the BeforeFieldChange and set the ProposedValue to null and voila! It worked.

1 Like