Wednesday, September 28, 2016

Change DataGridViewRow FontStyle to Bold in CellFormatting event

Hello,
There was a question raised in the forums on how to change the FontStyle of a DataGridViewRow to Bold in the CellFormatting event. A solution is to set the Font property of a row with a Font object setting it's second parameter to FontStyle.Bold.
private void EmployeeDTRDataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
 if (EmployeeDTRDataGridView.Columns[e.ColumnIndex].Name == "OnLeave")
 {
  if (e.Value != System.DBNull.Value)
  {
   if (Convert.ToBoolean(e.Value) == true)
   {
    EmployeeDTRDataGridView.Rows[e.RowIndex].DefaultCellStyle.Font = new Font(e.CellStyle.Font, FontStyle.Bold);
   }
  }
 }
}

0 comments:

Post a Comment