1 回答

TA貢獻1841條經驗 獲得超3個贊
這應該工作得更好:
private void dataGridView1_CellFormatting(object sender,
DataGridViewCellFormattingEventArgs e)
{
DataGridViewRow row = DGV_boiteReception.Rows[e.RowIndex];
if (row.Cells["vu"].Value != null )
{
e.CellStyle.Font = new Font(DGV_boiteReception.Font,
row.Cells[0].Value.ToString() == "False" ?
FontStyle.Bold : FontStyle.Regular);
}
}
我只設置了Font,而不是整個Style*(,并且我只按照建議更改了當前格式化單元格的樣式。
我還在測試單元格的值之前檢查是否為 null 并重置了字體樣式。
(*) 出于某種原因,這似乎與您看到的連續重繪有所不同。
如果您的單元格是一個Checkbox單元格,您還應該對這些事件進行編碼:
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
dataGridView1.Invalidate();
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
}
你不應該那樣True,False只是為了正常CheckBoxes。如果您將復選框設置為允許第三種狀態 ( ThreeState = true),則將是Checked,Unchecked和Indeterminate。
- 1 回答
- 0 關注
- 104 瀏覽
添加回答
舉報