我使用以下代码来更改datagridview的CellEnter事件中的单元格样式。但是,如果我删除if语句,在绑定数据后,所有行都将格式化为粗体。有什么建议或建议吗?
DataGridViewCellStyle oStyle = new DataGridViewCellStyle();
oStyle.Font = new Font("Microsoft Sans Serif", 9.25f, FontStyle.Bold);
if (e.RowIndex > 0)
{
dataGridView1.Rows[e.RowIndex].Cells[0].Style = oStyle;
dataGridView1.Rows[e.RowIndex].Cells[1].Style = oStyle;
dataGridView1.Rows[e.RowIndex].Cells[2].Style = oStyle;
dataGridView1.Rows[e.RowIndex].Cells[3].Style = oStyle;
dataGridView1.Rows[e.RowIndex].Cells[4].Style = oStyle;
dataGridView1.Rows[e.RowIndex].Cells[5].Style = oStyle;
dataGridView1.Rows[e.RowIndex].Cells[6].Style = oStyle;
dataGridView1.Rows[e.RowIndex].Cells[7].Style = oStyle;
dataGridView1.Rows[e.RowIndex].Cells[8].Style = oStyle;
}发布于 2016-09-22 22:53:21
如果我没理解错的话,那就是你所期望的行为。您可以尝试将上述代码添加到CellMouseClick事件中。
https://stackoverflow.com/questions/39641644
复制相似问题