2016-07-11 4 views
-1

私のプロジェクトでこのコードを持っています。私はこのWebサイトのヘルプで行います。私のコードは、datagridviewcheckboxcolumnチェック状態をチェックした後、データグリービューの別のセルをチェックしてメソッドを実行するかどうかをチェックし、ボタンをクリックします。 私はそれが「year_student_update()」メソッドを実行しない]ボタンをクリックするが、第2に、それは仕事をクリックしたときに、これは私のコード私のコードは初めて実行されませんか?どうして?

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

です。誰も私を助けることができますか?

+0

Visual Studioを使用していますか? WPF? WinForms? ASPX? – GibralterTop

+0

yes visual studio 2013. winforms –

+0

ここで「sc」は定義されていますか? –

答えて

3

あなたの方法sc.year_student_update(...ifの条件if (cellValue(dgv_student_update.Rows[i], 3) == 1)の中にあり、おそらくそれはtrueではありません。コメントifブロックし、メソッドがヒットするかどうかを確認してください。もしそうなら、なぜあなたのifブロックが満足できないのかを調べるべきです。

+0

私はmessageBoxを入れると、メソッドの場所にあるifの中に最初のクリックでメッセージが表示されます。これは2つのifが真実であるということを意味します。 –

関連する問題