[英]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.