views:

2423

answers:

2

Hi, i have a problem with my code.

foreach (DataRow dr in dt_pattern.Rows)
    {
      part = dr["patternString"].ToString();
      if (part != vpart)
      {
        System.Console.WriteLine(part);
        System.Console.WriteLine("Geben Sie bitte für den Abschnitt die AT ein: ");
        temp = System.Console.ReadLine();
        AT = ToDouble(temp);
        dr["AT"] = AT;

        double xATmax = ToDouble(dr["Ampl"].ToString());
        double x = ToDouble(dr["Time"].ToString());

        double yATmax = ToDouble(dr["Ampl"]+1.ToString()) + AT;
        double y = ToDouble(dr["Ampl"].ToString());

        dr["alphaATmin"] = Gradient(x,xATmax,y,yATmax);
        System.Console.WriteLine(dr["alphaATmin"]);
      }
      vpart = part;          
    }

but i need at xATmax and yATmax the Value of the next Row... Someone can help me ?

+5  A: 

Dont use a foreach then. Use a 'for loop'. Your code is a bit messed up but you could do something like...

for (Int32 i = 0; i < dt_pattern.Rows.Count; i++)
{
    double yATmax = ToDouble(dt_pattern.Rows[i+1]["Ampl"].ToString()) + AT;
}

Note you would have to take into account during the last row there will be no 'i+1' so you will have to use an if statement to catch that.

Chalkey
+2  A: 
for (int i=0; i<dt_pattern.Rows.Count; i++)
{
    DataRow dr = dt_pattern.Rows[i];
}

In the loop, you can now reference row i+1 (assuming there is an i+1)

John Saunders