1

So I need to read from a file and display it all in a suitable format. So far I can read all the data in and it does show on the form however from the HRData it only reads in 1 full line and displays that on the form I need it to display every line from that specific part of the file. I've put down a snippet of my code where Iread from the file and display the HRData from that file, but I need every line to be in the table and not the repeat of the same line. Any Help would be appreciated. Sorry for the layout of my code I'm still trying the get used to stack over flow so apologies.

DateTime date = new DateTime(2014, 09, 08, 16, 0, 0);

string[] Data1 = Regex.Split(filetext, "HRData]");
Data1[1] = Data1[1].Trim();
string[] HRData = Regex.Split(Data1[1], "\r\n|\r\n");

dataGridView1.ColumnCount = 7;
dataGridView1.ColumnHeadersVisible = true;

DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();

columnHeaderStyle.BackColor = Color.Beige;
columnHeaderStyle.Font = new Font("Verdana", 10, FontStyle.Bold);
dataGridView1.ColumnHeadersDefaultCellStyle = columnHeaderStyle;

dataGridView1.Columns[0].Name = "Time";
dataGridView1.Columns[1].Name = "Heart Rate (bpm)";
dataGridView1.Columns[2].Name = "Speed";
dataGridView1.Columns[3].Name = "Cadence (rpm)";
dataGridView1.Columns[4].Name = "Altitude (m/ft)";
dataGridView1.Columns[5].Name = "Power (watts)";
dataGridView1.Columns[6].Name = "Power Balance";



if (Versionval == 106)
{
    String FindVersionMode = "VersionMode";
    int indexofVersionMode = filetext.IndexOf(FindVersionMode);
    VersionModeTypeA = filetext.Substring(indexofVersionMode + 5, 1);
    VersionModeTypeB = filetext.Substring(indexofVersionMode + 6, 1);
    VersionModeTypeC = filetext.Substring(indexofVersionMode + 7, 1);
    VersionModeTypeD = filetext.Substring(indexofVersionMode + 8, 1);
    VersionModeTypeE = filetext.Substring(indexofVersionMode + 9, 1);
    VersionModeTypeF = filetext.Substring(indexofVersionMode + 10, 1);
    VersionModeTypeG = filetext.Substring(indexofVersionMode + 11, 1);
    VersionModeTypeH = filetext.Substring(indexofVersionMode + 12, 1);

    //SpeedType = Int32.Parse(VModeTypeA);
    //CadenceType = Int32.Parse(VModeTypeA);
    //AltType = Int32.Parse(VModeTypeA);
    //PowerType = Int32.Parse(VModeTypeA);
    //PowerLRBType = Int32.Parse(VModeTypeA);
    //PowerPIType = Int32.Parse(VModeTypeA);
    // HRCCType = Int32.Parse(VModeTypeA);
    // EuroUsType = int.Parse(VModeTypeA);

    dataGridView1.Columns[3].Name = "Cadence (rpm)";
    dataGridView1.Columns[4].Name = "Altitude (m/ft)";
    dataGridView1.Columns[5].Name = "Power (watts)";
    dataGridView1.Columns[6].Name = "Power Balance";

}

    for (int i = 0; i < HRData.Length; i++)
    {

        date = date.AddSeconds(1);
        string[] HRDataColumn = Regex.Split(HRData[1], "\t");
        double speed1 = Int32.Parse(HRDataColumn[1]);
        speed1 = speed1 / 10;
        HRDataColumn[1] = speed1.ToString();
        dataGridView1.Rows.Add(date.ToString("HH:mm:ss"), HRDataColumn[0], HRDataColumn[1], HRDataColumn[2], HRDataColumn[3], HRDataColumn[4], HRDataColumn[5]);

}

[HRData] 91 154 70 309 83 6451 91 154 70 309 83 6451 92 160 75 309 87 5687 94 173 80 309 87 5687 96 187 87 309 95 4662 100 190 93 309 123 4407 101 192 97 309 141 4915 103 191 98 309 145 5429 106 190 99 309 157 4662

So this is a snippet of the HRData part of the file theirs a lot more data then that, but I cant paste all of it and so far my code only reads in the first line successfully in each column of the table. Keeps repeating the same line. so the first line that keeps repeating is: 91 154 70 309 83 6451

Thanks

1 Answer 1

0

You are always using the same string array HRDataColumn

string[] HRDataColumn = Regex.Split(HRData[1], "\t");

Try to change this line to

string[] HRDataColumn = Regex.Split(HRData[i], "\t");
Sign up to request clarification or add additional context in comments.

1 Comment

omg thankyou so much it worked! i feel so stupid that it was only 1 thing i had to change. Thankyouuu

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.