簽到程式中,迴圈 for (int j = 1; j < Rows.Count; j++) 導致索引 0 的第一列永不處理,故「已簽到」不顯示。
for (int j = 0; j < dataGridView1.Rows.Count; j++) {
if (簽到觸發條件) {
dataGridView1.Rows[j].Cells[1].Value = "已簽到";
}
}
DataGridView.Rows 集合索引**從 0 開始**,Rows[0] 為第一列資料列(若 AllowUserToAddRows=true,最後一列為新增列,索引為 Count-1,需排除)。
int maxIndex = dataGridView1.AllowUserToAddRows ? dataGridView1.Rows.Count - 1 : dataGridView1.Rows.Count;
for (int j = 0; j < maxIndex; j++) { ... }