我在下面有此代码,该代码应在选中复选框中的复选框时显示消息框。我知道该行确实被选中,这对我来说是个考验。
如果这可行,我会将 SelectedRows 保存到数据库中。因此,在构建此代码时了解它可能会有所帮助。作为我的初学者,我想问你们为什么当我检查复选框时MessageBox不出现?提前非常感谢。
  DataGridViewCheckBoxColumn chk = new DataGridViewCheckBoxColumn();
  dtg_ksluzby.Columns.Add(chk);
  dtg_ksluzby.Columns[3].Width = 20;
  foreach (DataGridViewRow row in dtg_ksluzby.Rows)
  {
      // number 3 represents the 4th column of dgv
      DataGridViewCheckBoxCell chk1 = row.Cells[3] as DataGridViewCheckBoxCell; 
      if (Convert.ToBoolean(chk1.Value) == true)
      {
         MessageBox.Show("this cell checked");
      }
      else
      {
      }
  }