2014-05-06 119 views
0

對於如何用單圈數作爲行和單圈時間填充我的datagridview作爲列,我無能爲力。我會非常感謝任何建議。這裏是我的比賽圈數和時間陣列的代碼:用雙精度數組填充datagridview(行)

public double[] LapTimes_Method(int NumLaps, double LapTime) 
{ 
    double[] raceLapArray = new double[NumLaps]; 
    for (int x = 0; x < NumLaps; x++) 
    { 
     Random Random_Numbers = new Random(DateTime.Now.Millisecond); 
     double RandomLapNumber; 
     RandomLapNumber = Random_Numbers.Next(98, 102)/100; 
     double RandomTime; 
     RandomTime = LapTime * RandomLapNumber; 
     raceLapArray[x] = RandomTime; 
    } 
    return raceLapArray; 
} 

我爲這種混亂道歉。這裏就是我試圖用不同的圈數來填充的DataGridView行的代碼:

private void dgd_Simulation_Results_CellContentClick(object sender, DataGridViewCellEventArgs e) 
    { 
     Simulation_Calculations Name2; 
     Name2 = new Simulation_Calculations(); 

     int input; 
     bool isInt = int.TryParse(text_S_NumLaps.Text, out input); 

     double input2; 
     bool isDouble = double.TryParse(text_S_Lap_Time.Text, out input2); 

     double[] raceLapArray; 

     if (isInt == true && isDouble == true) 
     { 

      raceLapArray = Name2.LapTimes_Method(input, input2); 
      dgd_Simulation_Results.Rows[e.RowIndex].Cells[input].Value = "Lap" + input; 

     } 
     DataGridColumnStyle.Equals(input, input2); 
    } 
+0

代碼沒有問題。我不知道如何用存儲的值填充我的datagridview。以Numlaps爲行,LapTime爲列。 – Jcannon99

+0

填充datagridview的代碼是什麼樣的?你試過什麼了?你知道如何填充這種類型的控件嗎?您嘗試顯示哪種類型的數據。 **你問的問題是什麼?** – gunr2171

+0

我試圖像列表框一樣填充dgd,但這顯然不起作用:'dgd_Simulation_Results.NewRowIndex.Equals(「Lap」+(x + 1)); dgd_Simulation_Results.Columns.Add(raceLapArray [x]);' 。我試圖顯示字符串「LapNumber」作爲行,並在每個相應的「LapNumber」旁邊有一個「Laptime」。 – Jcannon99

回答

0

要填充一個DataGridView,在一般使用:

for(your condition) 
{ 
datagridviewName.Rows.Add(column1 value, column2 value, column3 value... etc); 
} 

在你的情況下,對於循環條件語句將解析通過你的數組。

對於列值,您可以將它放在您想要在適當的dgv列中輸出的索引值中。 (array [0],array [1]等)

+0

好的謝謝你的答覆。我會嘗試這種方法。 – Jcannon99