用双精度数组填充datagridview (Rows)
本文关键字:Rows datagridview 填充 双精度 数组 | 更新日期: 2023-09-27 18:02:06
我不知道如何用圈数作为行,圈时间作为列来填充我的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);
}
填充datagridview,一般使用:
for(your condition)
{
datagridviewName.Rows.Add(column1 value, column2 value, column3 value... etc);
}
在您的示例中,For循环条件语句将解析整个数组。
对于列值,您可以在相应的dgv列中放置想要输出的索引值。(array[0], array[1]等)