Custom EpiDataView-how to add row

I have a custom EpiDataView I created using the following code:

EpiDataView edvCC = new EpiDataView();
DataTable dt = new DataTable();
//added columns like dt.Columns.Add(new DataColumn("Date", typeof(DateTime)));
edvCC.dataView = dt.DefaultView;
oTrans.Add("edvCC", edvCC);

This all works just fine and I am able to bind custom controls to the new dataview.
I am unable to actually interact with the dataview though, given that the row is -1 and all my bound controls are obviously then set to read only because the dataview doesn’t have any data.

Is there a trick to getting this to work?

Something like this?

 DataRow newRow = dt.NewRow();
 newRow["Date"] = "SOMEDATE HERE";
 dt.Rows.Add(newRow);

I tried doing that and I’m getting this error:
Value is neither a DataColumn nor a DataRelation for table .
I’m typing the column name exactly as it appears, so not sure…

add the column as well. You have the line commented out.
DataColumn Date = dt.Columns.Add(“Date”, System.Type.GetType(“System.String”));

I only commented it in this example, in my code it’s not commented.

@josecgomez posted something last week.

http://trigemco.com/add-a-custom-epidataview-in-an-epicor-customization/

1 Like

This is actually where I got a lot of the code from. Like I said, I have no problems adding the epidataview itself and binding controls to it. My problem lies in that I cannot seem to access or set any of the fields in the dataview because there is no data in it. I’m wondering how to set data in the new epidataview

I know this works for us… It looks like what you are using. The foreach loop is a BAQ results.

Then we epiBound to the control or grid. sorry I might not be helping.

public static DataTable ParentRevs = new DataTable();
DataColumn Revision = ParentRevs.Columns.Add("Revision", System.Type.GetType("System.String"));
DataColumn IsApproved = ParentRevs.Columns.Add("IsApproved", System.Type.GetType("System.String"));
DataColumn EffectiveDate = ParentRevs.Columns.Add("EffectiveDate", System.Type.GetType("System.String"));

foreach (DataRow row in results.Rows)
{
	DataRow newRow = ParentRevs.NewRow();

	newRow["Revision"] = row["Calculated_Revision"];
	newRow["IsApproved"] = row["Calculated_IsApproved"];
	newRow["EffectiveDate"] = row["Calculated_EffectiveDate"];

	ParentRevs.Rows.Add(newRow);
}
1 Like

Not at all, I really appreciate the dialog! I am unfortunately at a loss on this one, but I’m sure it’s something incredibly simple that I am missing.
It seems that I experience the exception when I add the row both during the initialization of the code OR calling it from the Form Load event, which leads me to believe that it’s quite angry with something. I get the error 3 times, so that makes me think it’s related to the three columns that I’m defining a datatype other than string

EpiDataView edvOrderHed, edvCC;
DataTable dt;

edvCC = new EpiDataView();
		dt = new DataTable();
		dt.Columns.Add(new DataColumn("Date", typeof(DateTime)));
		dt.Columns.Add(new DataColumn("Customer"));
		dt.Columns.Add(new DataColumn("CustNum"));
		dt.Columns.Add(new DataColumn("Phone"));
		dt.Columns.Add(new DataColumn("BillToZip"));
		dt.Columns.Add(new DataColumn("CardType"));
		dt.Columns.Add(new DataColumn("CardNum"));
		dt.Columns.Add(new DataColumn("ExpDate", typeof(DateTime)));
		dt.Columns.Add(new DataColumn("CVCNum"));	
		dt.Columns.Add(new DataColumn("CardholderName"));
		dt.Columns.Add(new DataColumn("OrderTotal", typeof(decimal)));
		dt.Columns.Add(new DataColumn("OrderNum"));
		dt.Columns.Add(new DataColumn("PONum"));
		dt.Columns.Add(new DataColumn("TakenBy"));

		edvCC.dataView= dt.DefaultView;
		oTrans.Add("edvCC", edvCC);

then try it without them. :wink:

see if it works… then figure out how to add them if needed

1 Like

See this is why being the only developer at my company is sometimes a bad thing. No one to tell me not to be so stubborn!! :slight_smile: I’ll play around with it and see if that works, thanks Ken

1 Like

Check out this link. Might help…

public DataTable MakeDataTable(){`

    DataTable myTable;
    DataRow myNewRow; 
    // Create a new DataTable.
    myTable = new DataTable("My Table");

    // Create DataColumn objects of data types.
    DataColumn colString = new DataColumn("StringCol");
    colString.DataType = System.Type.GetType("System.String");
    myTable.Columns.Add(colString); 

    DataColumn colInt32 = new DataColumn("Int32Col");
    colInt32.DataType = System.Type.GetType("System.Int32");
    myTable.Columns.Add(colInt32);

    DataColumn colBoolean = new DataColumn("BooleanCol");
    colBoolean.DataType = System.Type.GetType("System.Boolean");
    myTable.Columns.Add(colBoolean);

    DataColumn colTimeSpan = new DataColumn("TimeSpanCol");
    colTimeSpan.DataType = System.Type.GetType("System.TimeSpan");
    myTable.Columns.Add(colTimeSpan);

    DataColumn colDateTime = new DataColumn("DateTimeCol");
    colDateTime.DataType = System.Type.GetType("System.DateTime");
    myTable.Columns.Add(colDateTime);

    DataColumn colDecimal = new DataColumn("DecimalCol");
    colDecimal.DataType = System.Type.GetType("System.Decimal");
    myTable.Columns.Add(colDecimal);

    DataColumn colByteArray = new DataColumn("ByteArrayCol");
    colByteArray.DataType = System.Type.GetType("System.Byte[]");
    myTable.Columns.Add(colByteArray);


    // Populate one row with values.
    myNewRow = myTable.NewRow();

    myNewRow["StringCol"] = "Item Name";
    myNewRow["Int32Col"] = 2147483647;
    myNewRow["BooleanCol"] = true;
    myNewRow["TimeSpanCol"] = new TimeSpan(10,22,10,15,100);
    myNewRow["DateTimeCol"] = System.DateTime.Today;
    myNewRow["DecimalCol"] = 64.0021;
    myNewRow["ByteArrayCol"] = new Byte[] { 1, 5, 120 };
    myTable.Rows.Add(myNewRow);
    return myTable;  
 }

Well I tried this with using the code above and I got exactly the same result.
I wonder how other devs are doing this…hmm

does it work for just strings?

when does it error out? right away or when you add the row? I am trying to duplicate this here.

I tried unbinding the 3 columns from the controls that are not strings and did not add them to the datatable. I still get the error at runtime.

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 **
	EpiDataView edvOrderHed, edvCC;
	DataTable dt;

	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.btnPreview.Click += new System.EventHandler(this.btnPreview_Click);
		// End Wizard Added Custom Method Calls
		//Define Credit Card EpiDataView
		edvCC = new EpiDataView();
		dt = new DataTable();
		//for columns with special datatype, add this way
		//Order Date
		DataColumn dateCol = new DataColumn("Date");
		dateCol.DataType = System.Type.GetType("System.DateTime");
		//Expire Date
		DataColumn expDateCol = new DataColumn("ExpDate");
		expDateCol.DataType = System.Type.GetType("System.DateTime");
		//Order Total
		DataColumn orderTotalCol = new DataColumn("OrderTotal");
		orderTotalCol.DataType = System.Type.GetType("System.Decimal");
		//then add them to datatable columns	
		//dt.Columns.Add(dateCol);
		//dt.Columns.Add(expDateCol);
		//dt.Columns.Add(orderTotalCol);

		//Standard String Columns
		//dt.Columns.Add(new DataColumn("Date"));
		dt.Columns.Add(new DataColumn("Customer"));
		dt.Columns.Add(new DataColumn("CustNum"));
		dt.Columns.Add(new DataColumn("Phone"));
		dt.Columns.Add(new DataColumn("BillToZip"));
		dt.Columns.Add(new DataColumn("CardType"));
		dt.Columns.Add(new DataColumn("CardNum"));
		//dt.Columns.Add(new DataColumn("ExpDate"));
		dt.Columns.Add(new DataColumn("CVCNum"));	
		dt.Columns.Add(new DataColumn("CardholderName"));
		//dt.Columns.Add(new DataColumn("OrderTotal"));
		dt.Columns.Add(new DataColumn("OrderNum"));
		dt.Columns.Add(new DataColumn("PONum"));
		dt.Columns.Add(new DataColumn("TakenBy"));


		//Add Row to DataTable
		DataRow defaultRow = dt.NewRow();
		defaultRow["Customer"] = "DEFAULT";
//		defaultRow["ExpDate"] = System.DateTime.Now;
//		defaultRow["OrderTotal"] = 0.00;
		dt.Rows.Add(defaultRow);

		edvCC.dataView= dt.DefaultView;
		oTrans.Add("edvCC", edvCC);
		
		//set drop down style
		//this.cmbCardType.DropDownStyle = Infragistics.Win.UltraWinGrid.UltraComboStyle.DropDownList;
	}

hmm. something is going on.

the following didn’t complain for me. I checked it out after the table was loaded and the data was there as expected.

public static DataTable ParentRevs = new DataTable();
DataColumn Revision = ParentRevs.Columns.Add("Revision", System.Type.GetType("System.String"));
DataColumn IsApproved = ParentRevs.Columns.Add("IsApproved", System.Type.GetType("System.String"));
DataColumn EffectiveDate = ParentRevs.Columns.Add("EffectiveDate", System.Type.GetType("System.String"));
DataColumn EffectiveDate2 = ParentRevs.Columns.Add("EffectiveDate2", System.Type.GetType("System.DateTime"));


foreach (DataRow row in results.Rows)
{
	DataRow newRow = ParentRevs.NewRow();

	newRow["Revision"] = row["Calculated_Revision"];
	newRow["IsApproved"] = row["Calculated_IsApproved"];
	newRow["EffectiveDate"] = row["Calculated_EffectiveDate"];
	newRow["EffectiveDate2"] = Convert.ToDateTime(row["Calculated_EffectiveDate"]);
	ParentRevs.Rows.Add(newRow);
	
}

Don’t name your column “Date” and see if it makes a difference.I can’t remember if there are reserved words here.

Same result, unfortunately.

post the runtime error please.