1 回答

TA貢獻(xiàn)1841條經(jīng)驗(yàn) 獲得超3個(gè)贊
這應(yīng)該工作得更好:
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);
}
}
我只設(shè)置了Font,而不是整個(gè)Style*(,并且我只按照建議更改了當(dāng)前格式化單元格的樣式。
我還在測(cè)試單元格的值之前檢查是否為 null 并重置了字體樣式。
(*) 出于某種原因,這似乎與您看到的連續(xù)重繪有所不同。
如果您的單元格是一個(gè)Checkbox單元格,您還應(yīng)該對(duì)這些事件進(jìn)行編碼:
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
dataGridView1.Invalidate();
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
}
你不應(yīng)該那樣True,F(xiàn)alse只是為了正常CheckBoxes。如果您將復(fù)選框設(shè)置為允許第三種狀態(tài) ( ThreeState = true),則將是Checked,Unchecked和Indeterminate。
- 1 回答
- 0 關(guān)注
- 94 瀏覽
添加回答
舉報(bào)