Hi ,
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
this.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
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
Font currentFont = e.CellStyle.Font;
Font newFont = new Font(currentFont.FontFamily, 11, currentFont.Style | FontStyle.Bold);
e.CellStyle.Font = newFont;
base.OnEditingControlShowing(e);
}
protected override void OnCellEndEdit(DataGridViewCellEventArgs e)
{
base.OnCellEndEdit(e);
this.CurrentCell.Style.ForeColor = Color.FromArgb(0, 0, 0);
protected override void OnCellLeave(DataGridViewCellEventArgs e)
{
base.OnCellLeave(e);
this.CurrentCell.Style.ForeColor = Color.FromArgb(0, 0, 0);
}
The above is the code i am using to create cell styles in datagridview . The only problem left in this , is that the white forecolor which gets set during the oneditingcontrolshowing cannot gets changed untill the row gets changed . i tried changing it in the oncellendedit and even in cell leave but it doesn't change . Can you please suggest why the white forecolor don't gets changed untill focus leaves the current row .