
ติ๊กแล้วขึ้นสี
พอติ๊กออกก็ให้สีหาย
ใน cell DataGridViewCheckBoxColumn ให้ระบุ FalseValue และ TrueValue ดังรูป

ใส่โค้ด:
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (dataGridView1.Rows[e.RowIndex].Cells["Column1"].Value.ToString () == "1")
dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.LightYellow; //ระบุสีตามใจชอบครับ
else
dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = dataGridView1.DefaultCellStyle.BackColor;
}
private void dataGridView1_CurrentCellDirtyStateChanged(object sender, EventArgs e)
{
if (dataGridView1.IsCurrentCellDirty)
dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
}
No comments:
Post a Comment