It seems that everything is ok with your code,when I use it it do exactly what it should do ,
but you have to check sales_dataGridView properties for DefaultCellStyle try:
sales_dataGridView1.DefaultCellStyle.BackColor = Color.White;
sales_sales_dataGridView1.DefaultCellStyle.ForeColor = Color.Black;
sales_dataGridView1.DefaultCellStyle.SelectionBackColor = Color.Red;
sales_dataGridView1.DefaultCellStyle.SelectionForeColor = Color.white;
This code should be typed in the program,
from where it has an influence on the whole program, in my case
public partial class MainForm : Form
dataGridView1.DefaultCellStyle.BackColor = Color.White;
dataGridView1.DefaultCellStyle.ForeColor = Color.Black;
dataGridView1.DefaultCellStyle.SelectionBackColor = Color.Red;
dataGridView1.DefaultCellStyle.SelectionForeColor = Color.White;
void Button1Click(object sender, EventArgs e)
After inserting the four lines of code, and if at no point throughout the program you did not have changed,
the result should be:
cell color after the selection of cell by clicking on it is red,
cell color after entering into it for editing content,by double clicking on it or by pressing enter is white,
text color is always black and the color of the cell that is not selected is white.
If the problem still occurs that DataGridView background color matches the color of the text when you enter the cell to modify the content, then you should check all the places in the program, for eventually inserted code for change of colors.
If the program is made in Visual Tool, where you just insert DataGridView from the Tool panel onto the Mainform,
check the properties for DataGridView DefaultCellStyle ,and check the properties in EditColumns Dialog for DataGridView DefaultCellStyle.Sometimes the color settings in these two different options are different from the settings in the program code and can override simetimes the program code if you use Reset command or Refresh command somewhere in the program.
Also, the difference in settings of colors in properties for DataGridView DefaultCellStyle , and the properties in EditColumns Dialog for DataGridView DefaultCellStyle usually results with unresolved error in program,
which you don't see (program running is apparently normal ,but it have errors).
This applies to all settings in those two properties for DataGredView control.
All the best,