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

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

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

4条回答
  •  自闭症患者
    2021-02-20 11:02

    After loading the contents in Datagrid, apply these event handlers to RowEnter and RowLeave.

    private void dg_RowEnter(object sender, DataGridViewCellEventArgs e)
    {
        System.Windows.Forms.DataGridViewCellStyle boldStyle = new System.Windows.Forms.DataGridViewCellStyle();
        boldStyle.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold);
        dg.Rows[e.RowIndex].DefaultCellStyle = boldStyle;
    }
    
    private void dg_RowLeave(object sender, DataGridViewCellEventArgs e)
    {
        System.Windows.Forms.DataGridViewCellStyle norStyle = new System.Windows.Forms.DataGridViewCellStyle();
        norStyle.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular);
        dg.Rows[e.RowIndex].DefaultCellStyle = norStyle;
    }
    

    Codes are not tested. But it should work fine.

    Hope it helps.

提交回复
热议问题