Hi @ankit goel , Welcome to Microsoft Q&A,
I used your code and it didn't appear that the current grid cannot be modified. To make all cells bold just use the OnCellFormatting event. The main code examples are as follows:
using System.Drawing;
using System.Windows.Forms;
namespace _10_30_x
{
public partial class CustomControl2 : DataGridView
{
public CustomControl2()
{
InitializeComponent();
this.EnableHeadersVisualStyles = false;
this.ColumnHeadersDefaultCellStyle.Font = new Font("Tahoma", 9.75F, FontStyle.Bold); // HEADER FONT BOLD
this.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; // fill the blank area
this.BackgroundColor = Color.FromArgb(250, 243, 198); // extra area color
this.DefaultCellStyle.SelectionBackColor = Color.FromArgb(168, 201, 170); // full row select color to green
this.RowsDefaultCellStyle.BackColor = Color.FromArgb(250, 243, 198);
// rows back color
this.ColumnHeadersDefaultCellStyle.BackColor = Color.FromArgb(250, 243, 198); // change back color of header cells
}
protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
}
protected override void OnCellFormatting(DataGridViewCellFormattingEventArgs e)
{
base.OnCellFormatting(e);
if (e.Value != null && e.RowIndex >= 0 && e.ColumnIndex >= 0)
{
Font newFont = new Font(e.CellStyle.Font.FontFamily, 11, e.CellStyle.Font.Style | FontStyle.Bold);
e.CellStyle.Font = newFont;
}
}
protected override void OnEditingControlShowing(DataGridViewEditingControlShowingEventArgs e)
{
// only place where it is working
e.CellStyle.BackColor = Color.FromArgb(0, 0, 0); // change cell color to black
e.CellStyle.ForeColor = Color.FromArgb(255, 255, 255); // change cell color to white
base.OnEditingControlShowing(e);
}
}
}
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.