C# 使用条件语句填充datagridview中的单元格
我有一个datagrid,其中填充了从变量中获取的数据。这些包括测试分数和平均时间值。我想根据其他列中的数据自动填充其中一列 我曾试图组合一个条件语句,如代码中所示,但第5列仍然显示为空C# 使用条件语句填充datagridview中的单元格,c#,datagridview,conditional-statements,C#,Datagridview,Conditional Statements,我有一个datagrid,其中填充了从变量中获取的数据。这些包括测试分数和平均时间值。我想根据其他列中的数据自动填充其中一列 我曾试图组合一个条件语句,如代码中所示,但第5列仍然显示为空 foreach (DataGridViewRow row in dataGridView1.Rows) { foreach (DataGridViewCell cell in row.Cells)
foreach (DataGridViewRow row in dataGridView1.Rows)
{
foreach (DataGridViewCell cell in row.Cells)
{
if (time > 20)
{
row.Cells[5].Value = "Beginner";
}
else if (time < 20 )
{
row.Cells[5].Value = "Intermediate";
}
}
foreach(dataGridView1.Rows中的DataGridViewRow行)
{
foreach(row.Cells中的DataGridViewCell单元格)
{
如果(时间>20)
{
row.Cells[5].Value=“初学者”;
}
否则如果(时间<20)
{
行。单元格[5]。Value=“中间”;
}
}
时间变量的值是多少?时间取自5个整数输入,是这5个时间的平均值。您是否尝试过调试,比如在循环中放置一个断点,然后查看实际流程?只是尝试了一下-没有真正的帮助。谢谢。