Setting field in EpiDataView not working

So I’m trying to be a good EpiCitizen, and update EDV rather than the textbox on screen. I have the following, but it doesn’t blank out the visible TextBox value or cause it to be saved.

private static void btnClearQASample_Click(object sender, System.EventArgs args)
{
	EpiDataView edvPart = ((EpiDataView)(Script.oTrans.EpiDataViews["Part"]));
	System.Data.DataRow edvPartRow = edvPart.CurrentDataRow;

	edvPartRow["SamplePartNum_c"] = String.Empty;
}

Am I missing a NotifyAll, or BeginEdit or something like that?

Thanks!

edvPart.CurrentDataRow["SamplePartNum_c"] = String.Empty;
This is how I do it (Which is the same)

It works just fine. Is the button doing anything?

  1.  EpiDataView edvPart = ((EpiDataView)(this.oTrans.EpiDataViews["Part"]));
     var edvPartRow = edvPart.CurrentDataRow;		
     edvPartRow["Attribute_c"] = String.Empty;
    
  2.  EpiDataView edvPart = ((EpiDataView)(this.oTrans.EpiDataViews["Part"]));
     var edvPartRow = edvPart.CurrentDataRow;
     edvPartRow.BeginEdit();		
     edvPartRow["Attribute_c"] = String.Empty;
     edvPartRow.EndEdit();
    

So a bit more backround. It’s on the Part screen, and I want to prevent typing into the EpiTextBox and instead force a Search. The Search massively limits the list of available parts. This all works fine. But because the EpiTextBox is ReadOnly/Disabled - I have to have a separate button to perform the Clear of this field if it is no longer required on the Part record.

image

Just tweaked it slightly to match the wizard provided code:

private static void SearchOnPartAdapterShowDialog()
	{
		// Wizard Generated Search Method
		// You will need to call this method from another method in custom code
		// For example, [Form]_Load or [Button]_Click

		bool recSelected;
		string whereClause = "PartNum LIKE '%QA'";
		System.Data.DataSet dsPartAdapter = Ice.UI.FormFunctions.SearchFunctions.listLookup(Script.oTrans, "PartAdapter", out recSelected, true, whereClause);
		if (recSelected)
		{
			System.Data.DataRow adapterRow = dsPartAdapter.Tables[0].Rows[0];

			// Map Search Fields to Application Fields
			EpiDataView edvPart = ((EpiDataView)(Script.oTrans.EpiDataViews["Part"]));
			System.Data.DataRow edvPartRow = edvPart.CurrentDataRow;
			if ((edvPartRow != null))
			{
				edvPartRow.BeginEdit();
				edvPartRow["SamplePartNum_c"] = adapterRow["PartNum"];
				edvPartRow.EndEdit();
			}
		}
	}

	private static void btnLabSample_Click(object sender, System.EventArgs args)
	{
		SearchOnPartAdapterShowDialog();
	}

	private static void btnClearQASample_Click(object sender, System.EventArgs args)
	{
		EpiDataView edvPart = ((EpiDataView)(Script.oTrans.EpiDataViews["Part"]));
		System.Data.DataRow edvPartRow = edvPart.CurrentDataRow;
		
		if ((edvPartRow != null))
		{
			edvPartRow.BeginEdit();
			edvPartRow["SamplePartNum_c"] = String.Empty;
			edvPartRow.EndEdit();
		}
		
	}

Still no joy :roll_eyes:

my working code as below

public class Script
{
// ** Wizard Insert Location - Do Not Remove ‘Begin/End Wizard Added Module Level Variables’ Comments! **
// Begin Wizard Added Module Level Variables **

// End Wizard Added Module Level Variables **

// Add Custom Module Level Variables Here **

public void InitializeCustomCode()
{
	// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
	// Begin Wizard Added Variable Initialization

	// End Wizard Added Variable Initialization

	// Begin Wizard Added Custom Method Calls

	this.btnClickMe.Click += new System.EventHandler(this.btnClickMe_Click);
	this.btnSearchPart.Click += new System.EventHandler(this.btnSearchPart_Click);
	SetExtendedProperties();
	// End Wizard Added Custom Method Calls
}

public void DestroyCustomCode()
{
	// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
	// Begin Wizard Added Object Disposal

	this.btnClickMe.Click -= new System.EventHandler(this.btnClickMe_Click);
	this.btnSearchPart.Click += new System.EventHandler(this.btnSearchPart_Click);
	// End Wizard Added Object Disposal

	// Begin Custom Code Disposal

	// End Custom Code Disposal
}

private void btnClickMe_Click(object sender, System.EventArgs args)
{
	// ** Place Event Handling Code Here **
	EpiDataView edvPart = ((EpiDataView)(this.oTrans.EpiDataViews["Part"]));
	var edvPartRow = edvPart.CurrentDataRow;
	edvPartRow.BeginEdit();		
	edvPartRow["Attribute_c"] = String.Empty;
	edvPartRow.EndEdit();
}

private void SearchPart()
{
	// Wizard Generated Search Method
	// You will need to call this method from another method in custom code
	// For example, [Form]_Load or [Button]_Click

	bool recSelected;
	string whereClause = string.Empty; // "PartNum LIKE '%QA'"; //disabled becuase it is not applicable for my environment
	System.Data.DataSet dsPartAdapter = Ice.UI.FormFunctions.SearchFunctions.listLookup(this.oTrans, "PartAdapter", out recSelected, true, whereClause);
	if (recSelected)
	{
		System.Data.DataRow adapterRow = dsPartAdapter.Tables[0].Rows[0];

		EpiDataView edvPart = ((EpiDataView)(this.oTrans.EpiDataViews["Part"]));
		// Map Search Fields to Application Fields
		System.Data.DataRow edvPartRow = edvPart.CurrentDataRow;
		if ((edvPartRow != null))
		{
			edvPartRow.BeginEdit();
			edvPartRow["Attribute_c"] = adapterRow["PartNum"];
			edvPartRow.EndEdit();
		}
	}
}

private void btnSearchPart_Click(object sender, System.EventArgs args)
{
	SearchPart();
}

private void SetExtendedProperties()
{
	// Begin Wizard Added EpiDataView Initialization
	EpiDataView edvPart = ((EpiDataView)(this.oTrans.EpiDataViews["Part"]));
	// End Wizard Added EpiDataView Initialization

	// Begin Wizard Added Conditional Block
	if (edvPart.dataView.Table.Columns.Contains("Attribute_c"))
	{
		// Begin Wizard Added ExtendedProperty Settings: edvPart-Attribute_c
		// edvPart.dataView.Table.Columns["Attribute_c"].ExtendedProperties["ReadOnly"] = true;
		edvPart.dataView.Table.Columns["Attribute_c"].ExtendedProperties["Enabled"] = false;
		// End Wizard Added ExtendedProperty Settings: edvPart-Attribute_c
	}
	// End Wizard Added Conditional Block
}

}

1 Like

Your code is the same as mine from what I can see?

difference between your and min static class and methods.

I tried changing the method away from Static, but get this error:

Compiling Custom Code ... 

----------errors and warnings------------

 Error: CS0708 - line 245 (4267) - 'btnClearQASample_Click': cannot declare instance members in a static class

 ** Compile Failed. **

I don’t want to change the Class definition, because it’s the base Epicor form.

Flip sake, it’s an Epicor bug!!!

public static void InitializeCustomCode()
	{
		// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
		// Begin Wizard Added Variable Initialization

		// End Wizard Added Variable Initialization

		// Begin Wizard Added Custom Method Calls

		CreateRowRulePartTypeCodeNotEqual_M();;
		SetExtendedProperties();
		Script.btnEngPrintLabel.Click += new System.EventHandler(Script.btnEngPrintLabel_Click);
		Script.btnLabSample.Click += new System.EventHandler(Script.btnLabSample_Click);
		Script.btnLabSample.Click += new System.EventHandler(Script.btnClearQASample_Click);

		// End Wizard Added Custom Method Calls
	}

	public static void DestroyCustomCode()
	{
		// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
		// Begin Wizard Added Object Disposal

		Script.btnEngPrintLabel.Click -= new System.EventHandler(Script.btnEngPrintLabel_Click);
		Script.btnLabSample.Click -= new System.EventHandler(Script.btnLabSample_Click);
		Script.btnLabSample.Click -= new System.EventHandler(Script.btnClearQASample_Click);
		// End Wizard Added Object Disposal

		// Begin Custom Code Disposal

		// End Custom Code Disposal
	}

When using the wizard it appears to have messed up the event handlers init!! The method was never being called!