我想将我指定的数据添加到列中,但出现错误“索引超出范围。必须为非负数且小于集合的大小。参数名称:索引”
private void Button1Click(object sender, EventArgs e)
{
var result = _transactionService.GetTransactionReport(DateTime.Now.AddDays(-2), DateTime.Now);
foreach (var transaction in result)
{
for (int r = 0; r < result.Count; r++)
{
dataGridView1.Rows[r].Cells[0].Value = transaction.Number;
dataGridView1.Rows[r].Cells[1].Value = transaction.DateTime;
dataGridView1.Rows[r].Cells[1].Value = transaction.Customer.Name;
}
}
}
如何将数据添加到行和列?