簡體   English   中英

我的代碼第一次不執行? 為什么?

[英]my code does not execute the at first time? why?

我在我的項目中有此代碼,並在此網站上提供了幫助,我的代碼在檢查了datagridview的另一個單元格之后檢查了datagridviewcheckboxcolumn的檢查狀態,以檢查其執行方法,我所有的代碼都在按鈕內點擊。 這是我的代碼

private void update_bt_Click(object sender, EventArgs e)
{
    var current_year = DateTime.Today.Year;
    var last_year = DateTime.Today.Year - 1;
    for (int i = 0; i < dgv_student_update.Rows.Count; i++)
    {
        Func<DataGridViewRow, int, int> cellValue = (row, j) =>
        {
            int.TryParse(row.Cells["stg_id"].Value.ToString(), out j);
            return j;
        };
        DataGridViewCheckBoxCell chkchecking = dgv_student_update.Rows[i].Cells["result"] as DataGridViewCheckBoxCell;
        if (Convert.ToBoolean(chkchecking.Value) == true)
        {
            //check if cell[3] in each row equal to stage id (1=first stage).
            if (cellValue(dgv_student_update.Rows[i], 3) == 1)
            {
                sc.year_student_update(
                Convert.ToInt32(dgv_student_update.Rows[i].Cells[1].Value),
                dgv_student_update.Rows[i].Cells[2].Value.ToString(), 2);
            }
        }
    }
}

當我單擊按鈕時,它不執行“ year_student_update()”方法,但是在第二次單擊時,它將執行該工作。 有人可以幫我嗎?

您的方法sc.year_student_update(...if條件if (cellValue(dgv_student_update.Rows[i], 3) == 1)並且很可能不是true 。注釋if塊,看看您的方法是否成功。因此,那么您應該檢查為什么您的if塊不令人滿意。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM