I am attempting to apply a white text color to the cells in alternate rows, but for some reason, the text appears black instead of white. Essentially, I aim to set the text color to white for each cell in the unselected or normal mode.
Could someone please assist me in resolving this issue? Below is the designer code for the DataGridView, also please look into the image first for a better understanding.
(Note: I am using the default DataGridView and not the
BunifuDataGridView. The variable name has not been changed yet, so
please consider the default DataGridView.)
//
// bunifuDataGridView
//
this.bunifuDataGridView.AllowUserToAddRows = false;
this.bunifuDataGridView.AllowUserToDeleteRows = false;
this.bunifuDataGridView.AllowUserToOrderColumns = true;
dataGridViewCellStyle1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(44)))), ((int)(((byte)(48)))), ((int)(((byte)(52)))));
dataGridViewCellStyle1.ForeColor = System.Drawing.Color.White;
this.bunifuDataGridView.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle1;
this.bunifuDataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.DisplayedCells;
this.bunifuDataGridView.BackgroundColor = System.Drawing.Color.FromArgb(((int)(((byte)(15)))), ((int)(((byte)(16)))), ((int)(((byte)(18)))));
this.bunifuDataGridView.CellBorderStyle = System.Windows.Forms.DataGridViewCellBorderStyle.SingleHorizontal;
this.bunifuDataGridView.ClipboardCopyMode = System.Windows.Forms.DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText;
this.bunifuDataGridView.ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.None;
dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(15)))), ((int)(((byte)(16)))), ((int)(((byte)(18)))));
dataGridViewCellStyle2.Font = new System.Drawing.Font("Segoe UI Semibold", 11.75F, System.Drawing.FontStyle.Bold);
dataGridViewCellStyle2.ForeColor = System.Drawing.Color.White;
dataGridViewCellStyle2.SelectionBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(63)))), ((int)(((byte)(63)))), ((int)(((byte)(65)))));
dataGridViewCellStyle2.SelectionForeColor = System.Drawing.Color.White;
dataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.bunifuDataGridView.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle2;
this.bunifuDataGridView.ColumnHeadersHeight = 40;
dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle3.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(33)))), ((int)(((byte)(37)))), ((int)(((byte)(41)))));
dataGridViewCellStyle3.Font = new System.Drawing.Font("Segoe UI Semibold", 9.75F, System.Drawing.FontStyle.Bold);
dataGridViewCellStyle3.ForeColor = System.Drawing.Color.White;
dataGridViewCellStyle3.SelectionBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(114)))), ((int)(((byte)(117)))), ((int)(((byte)(119)))));
dataGridViewCellStyle3.SelectionForeColor = System.Drawing.Color.WhiteSmoke;
dataGridViewCellStyle3.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
this.bunifuDataGridView.DefaultCellStyle = dataGridViewCellStyle3;
this.bunifuDataGridView.EditMode = System.Windows.Forms.DataGridViewEditMode.EditOnEnter;
this.bunifuDataGridView.EnableHeadersVisualStyles = false;
this.bunifuDataGridView.GridColor = System.Drawing.Color.FromArgb(((int)(((byte)(50)))), ((int)(((byte)(56)))), ((int)(((byte)(62)))));
this.bunifuDataGridView.Location = new System.Drawing.Point(10, 12);
this.bunifuDataGridView.Name = "bunifuDataGridView";
this.bunifuDataGridView.ReadOnly = true;
dataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle4.BackColor = System.Drawing.SystemColors.Control;
dataGridViewCellStyle4.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
dataGridViewCellStyle4.ForeColor = System.Drawing.SystemColors.WindowText;
dataGridViewCellStyle4.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle4.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle4.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.bunifuDataGridView.RowHeadersDefaultCellStyle = dataGridViewCellStyle4;
this.bunifuDataGridView.RowHeadersVisible = false;
this.bunifuDataGridView.RowTemplate.Height = 40;
this.bunifuDataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.CellSelect;
this.bunifuDataGridView.Size = new System.Drawing.Size(920, 479);
this.bunifuDataGridView.TabIndex = 11;
this.bunifuDataGridView.VirtualMode = true;
It’s .NET Framework, right? Try to set the ForeColor of the
RowTemplate.DefaultCellStyle
to the same value as the DefaultCellStyle.ForeColor. In previous versions of the Control, when the DGV is first initialized, the[DataGridView].DefaultCellStyle.ForeColor
may reset to its default value