当我选择一行时,如何使datagridview行文本以粗体显示?

Gal*_*ali 8 c# winforms

当我选择一行时,如何以粗体显示datagridview行文本?

Jul*_*lin 20

处理DataGridViewCellFormatting事件,并在单元格属于选定行时将粗体样式应用于字体:

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)