对C#的datagridview操作有点疑问
下面的代码是动态添加一个column,然后自动设置勾选,但是为啥运行之后没有一个是已经被勾选的了呢??
在MesageBox里明明有2个显示已经勾选了。。。
DataGridViewCheckBoxColumn c = new DataGridViewCheckBoxColumn(); c.HeaderText = "Mise En Vente"; c.Width = 150; c.Name = "venteCheckBox"; dataGridViewOeuvres.Columns.Add(c); for(int i=0; i< dataGridViewOeuvres.RowCount; ++i) { CheckBox ck = new CheckBox(); ck.Checked = Convert.ToInt32(dataGridViewOeuvres.Rows[i].Cells["miseEnVente"].Value)>0?true:false; dataGridViewOeuvres.Rows[i].Cells["venteCheckBox"].Value = ck; MessageBox.Show(dataGridViewOeuvres.Rows[i].Cells["venteCheckBox"].Value.ToString()); } dataGridViewOeuvres.CellClick += DataGridCellClick; void DataGridCellClick(object sender, DataGridViewCellEventArgs e) { if(dataGridViewOeuvres.Columns[e.ColumnIndex].Name == "venteCheckBox") { MessageBox.Show(dataGridViewOeuvres.Rows[e.RowIndex].Cells["venteCheckBox"].Value.ToString()); } }