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 关注
- 82 浏览
添加回答
举报