【发布时间】:2019-04-17 17:07:21
【问题描述】:
我正在尝试运行此代码,但出现异常:
索引超出范围。一定是 非负且小于 集合。参数名称:索引
private void LoadStudentGrades(int gradeParaleloId, int subjectId)
{
GradeStudentRepository gradeStudentRepo = new GradeStudentRepository();
students = gradeStudentRepo.FindAllGradeStudents().Where(g => g.GradeParaleloId == gradeParaleloId)
.Select(g => g.Student);
int i = 1;
foreach (var student in students)
{
DataGridViewRow row = new DataGridViewRow();
row.Cells[0].Value = i.ToString();
row.Cells[1].Value = student.LastNameFather + " " + student.LastNameMother + ", " + student.Name;
dataGridView1.Rows.Add(row);
i++;
}
}
我在 datagridview 中手动创建了列,现在我想使用这个小方法填充字段。
【问题讨论】:
-
您确定有可用于
datagridview1的列吗? -
什么意思 - “我在 datagridview 中手动创建了列”?您的意思是您在放置在表单上的 DataGridView 实例的“列”属性表中定义了列,还是您的意思是您在其他地方使用 C# 代码定义了列?
标签: c# .net datagridview