因此,我需要读取文件并以合适的格式显示所有文件。到目前为止,我可以读取所有数据,并且确实在窗体上显示,但是从HRData只能读取整行,并在窗体上显示,我需要它来显示文件特定部分的每一行。我在我从文件中读取并显示该文件的HRData处放了一段代码,但是我需要每一行都在表中,而不是同一行的重复。任何帮助,将不胜感激。对不起,我的代码布局我仍在尝试使用get来堆叠流过的方法,对此表示歉意。

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


因此,这是文件HRData部分的摘要,它们的内容很多,但是我无法粘贴所有内容,到目前为止,我的代码仅在表的每一列中成功读取了第一行。不断重复同一行。
因此,第一行重复的是:91 154 70 309 83 6451

谢谢

最佳答案

您始终使用相同的字符串数组HRDataColumn

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


尝试将此行更改为

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

关于c# - C#从文件加载数据并排序为数组,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42587707/

10-10 11:53