How to make the datagridview line text in bold when I pick a row?

后端 未结 4 2039
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-20 10:18

How do I make the datagridview line text in bold when I pick a row?

4条回答
  •  温柔的废话
    2021-02-20 10:47

    Handle the CellFormatting event of the DataGridView and apply a bold style to the font if the cell belongs to a selected row:

    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;
      }
    }
    

提交回复
热议问题