简体   繁体   English

我的代码第一次不执行? 为什么?

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

i have this code in my project that i do it with a help in this web site, my code check the datagridviewcheckboxcolumn checked state after that it checks another cell of datagridview with these to checks it execute a method, all my code is inside a button click. 我在我的项目中有此代码,并在此网站上提供了帮助,我的代码在检查了datagridview的另一个单元格之后检查了datagridviewcheckboxcolumn的检查状态,以检查其执行方法,我所有的代码都在按钮内点击。 this is my code 这是我的代码

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);
            }
        }
    }
}

when i click button it does not execute the "year_student_update()" method but at the second click it do the job. 当我单击按钮时,它不执行“ year_student_update()”方法,但是在第二次单击时,它将执行该工作。 anyone can help me please? 有人可以帮我吗?

您的方法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.

相关问题 为什么在第一个图片代码不执行,但在第二个呢? - Why on the first pic code doen't execute, but on the second it does? 为什么这不起作用? 不执行代码? - Why is this not working? Does not execute code? 为什么实体框架代码首先更改我的类型名称? - Why Does Entity Framework Code First Change my Type Names? 为什么语句在Toad中执行而在我的代码中不执行? - Why would a statement execute in Toad but not in my code? 为什么我的代码跳过我的控制台。在第一个之后读取? - Why does my code skip my Console.Read after the first one? 为什么我的排序行为仅在列表中只有一个项目时发生,并且只有在第一次添加集合时才发生? - Why does my sort behavior fire with only one item in the list, and only the first time the collection is added to? 为什么我的UpdateAsync(用户)方法第一次失败,声称用户不存在? - Why does my UpdateAsync(user) method fail the first time, claiming user doesn't exist? 为什么Main(string [] args)函数总是先执行,即在代码中出现的任何其他函数之前执行 - Why does the Main(string[] args) function always execute first , ie., before any other function present in the code 为什么我的MVC Razor仅在第一次返回视图时才填充HTML表? - Why does my MVC Razor populate the HTML table only the first time the view is returned? 为什么第二个for循环总是比第一个循环执行得快? - Why does the second for loop always execute faster than the first one?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM