您好,
或許可以在 DataGridView 的 CellClick 事件裡處理,類似如下,
private void Form1_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable("t1");
dt.Columns.Add("c1", typeof(bool));
dt.Columns.Add("c2", typeof(string));
dt.Rows.Add(true, "c1");
dt.Rows.Add(false, "c2");
this.dataGridView1.DataSource = dt;
}
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex > -1 && e.ColumnIndex == 0)
{
DataGridViewCheckBoxCell cell = (DataGridViewCheckBoxCell)dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
dataGridView1.BeginEdit(true);
bool isChecked = Convert.ToBoolean( cell.Value);
cell.Value = !isChecked;
dataGridView1.EndEdit();
}
}
亂馬客blog: http://www.dotblogs.com.tw/rainmaker/