I know this is Probably obvious but I am new and stuck!!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • miggs
    New Member
    • Feb 2010
    • 2

    I know this is Probably obvious but I am new and stuck!!

    Here is my problem, please excuse my newbieness..

    I have a datagrid on a form where you can put in numbers for a spacing.
    I am trying to get the code to place the item at the first space dictated by the first row of the datagrid, then for the second row add that number to the first row etc.

    If you look at the picture what I want to do is place an item at 120 on the first row. Then the second Row I want to add that to the first one so the item would be placed at 240 inches. Then the third row added to the total of the first to so it would be at 360.

    Right now xVal is where the items are being placed.

    Here is the code I have so far which isnt right. It puts everything at 120 inches.
    Thanks

    Code:
    double xVal = 0;
                                            
    DataGridViewRow EndPostSpacing = d_Endpost.Rows[i];
    string PostSpacing = EndPostSpacing.Cells["EPSpacing"].Value.ToString();
    double PostSpacingTotal = I2M(double.Parse(PostSpacing.ToString()));
     if (PostSpacingTotal == 0)
     {
           if (xVal == 0)
     {
            PostSpacingTotal = 0;
      }
                                                                                            
      }
     xVal += PostSpacingTotal;
    Attached Files
  • miggs
    New Member
    • Feb 2010
    • 2

    #2
    Ok just an update.
    I have made a little progress with the added code. I can now add the first and second row together, but the third row only adds to the first and not the total of both. There is more to the for loop but this is the only portion that isn't working.

    (I2M is a method I have to convert metric to imperial)

    for (int i = 0; i < d_Endpost.Rows. Count -1 ; i++)
    {
    ///Sets Endpost Spacing


    DataGridViewRow EndPostSpacing = d_Endpost.Rows[i];
    Double xVal = 0;

    foreach(DataGri dViewRow row in d_Endpost.Rows)
    {
    string PostSpacing = EndPostSpacing. Cells["EPSpacing"].Value.ToString ();
    double PostSpacingTota l = I2M(double.Pars e(PostSpacing.T oString()));
    Double temp = PostSpacingTota l;
    if (i == 0)
    {
    xVal = temp;
    }
    else
    {
    xVal = temp += PostSpacingTota l;
    }

    }
    }

    Comment

    Working...