Jul*_*lin 20
处理DataGridView的CellFormatting事件,并在单元格属于选定行时将粗体样式应用于字体:
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
var dataGridView = sender as DataGridView;
if (dataGridView.Rows[e.RowIndex].Selected)
{
e.CellStyle.Font = new Font(e.CellStyle.Font, FontStyle.Bold);
// edit: to change the background color:
e.CellStyle.SelectionBackColor = Color.Coral;
}
}
Run Code Online (Sandbox Code Playgroud)