Solved

C# - looping through all rows in a dashboard grid

  • 7 December 2022
  • 5 replies
  • 565 views

Userlevel 1

I am working on a customized dashboard, trying to have it set a value for a field in all rows in the grid when the user clicks a button. I have defined an EpiDataView pointing to the grid, which compiles OK, but looping through all rows is causing me problems. I can get it to do it on selected rows using “foreach (var row in edvMyDataView.SelectedRows)” (thanks to the EUG community in a previous post) but so far I have been unable to get it to work for all rows. I have tried “foreach (var row in edvMyDataView.Rows)” but this doesn’t compile. Would be grateful for any assistance.

ERP 10.2.700.

Kind regards,

Peter

icon

Best answer by dan.ramirez 7 December 2022, 14:41

View original

5 replies

Userlevel 2

Try using a for statement instead of foreach

 

for (int i = 0; i < edvMyDataView.dataView.Count; i++)

{

   var eachRow = edvMyDataView.dataView[i];

}

Userlevel 2

You might need to play around with the correct statement to get the row count. I can’t remember if it’s .Count, .Rows, and if that is on the edv itself or in the .dataView property. I can review some past customizations and see if I can find it if you are not having any luck with any of these.

Userlevel 4

Here’s an example of database access in C# UI customization code, from another post here in the EUG forums:

 

EpiDataView edvInvDtl = ((EpiDataView)(oTrans.EpiDataViews["APInvDtl"]));

foreach(DataRow row in edvInvDtl.dataView.Table.Rows) 

{ // for each invoice line

  //declare variables to use in calculations

  double poRelQty = Convert.ToDouble(row["PORelQty"].ToString());

  double scrVendorQty = Convert.ToDouble(row["ScrVendorQty"].ToString());

  double scrUnitCost = Convert.ToDouble(row["ScrUnitCost"].ToString());

  double poUnitCost = Convert.ToDouble(row["POUnitCost"].ToString());

  double scrExtCost = Convert.ToDouble(row["ScrExtCost"].ToString());

  double poReceivedQty = Convert.ToDouble(row["POReceivedQty"].ToString());

  string partnum = Convert.ToString(row["PartNum"].ToString());

  if((poReceivedQty > poRelQty) && partnum != "Sales Tax")

  {

    holdInvoice = true;

  } // end if

  else if((scrUnitCost > (poUnitCost + 0.50)) && partnum != "Sales Tax")

  {

    holdInvoice = true;

  } // end else if

  else if((scrExtCost > Math.Round(((poRelQty * poUnitCost) + 0.50),2)) && partnum   != "Sales Tax")

  {

    holdInvoice = true;

  } // end else if

} // end for each invoice line

 

HTH,

… Monty.

Userlevel 1

Thanks Dan, it worked perfectly!

And it is as you said, .Count not .Rows.

Userlevel 1

Thanks Monty, this is exactly where I was trying to get to before Dan suggested a “for” statement. Both answers are spot on, just approaching the problem from different directions.

Reply