试试CellContentClick Event
private void dataGridViewCrossRef_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 25)
{
bool IsBool = false;
if (bool.TryParse(dataGridViewCrossRef[e.ColumnIndex, e.RowIndex].EditedFormattedValue.ToString(), out IsBool))
{
//Some code
}
}
}
编辑
试试这个,CellClick Event
你需要声明你dataTable
的public
private void dataGridViewCrossRef_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 25)
{
//Find primaykey or something unique from your dataTable
DataRow[] Rows = dataTable.Select("Id = '" + dataGridViewCrossRef[0, e.RowIndex].EditedFormattedValue.ToString() + "'");
Rows[0]["NameOfColumnHasCheckBox"] = !bool.Parse(Rows[0]["NameOfColumnHasCheckBox"].ToString());
}
}