There's a question about changing cell background color in a DataGridView programatically
But is there any way to set the background color for a particular column using the WinForms Designer?
There's a question about changing cell background color in a DataGridView programatically
But is there any way to set the background color for a particular column using the WinForms Designer?
Right click the DataGridView and select Edit Columns
Select the DefaultCellStyle Property and click on the Style Wizard
In the CellStyle Builder window, you can set whatever properties you'd like, including BackColor
What this will do is set the property inside of the form.designer.cs file during InitializeComponent()
private void InitializeComponent()
{
/// ...
this.ShadedColumn.DefaultCellStyle.BackColor = Color.Silver;
/// ...
}
<sup>* where this.ShadedColumn
is the name of the DataGridViewTextBoxColumn
control you added</sup>
Any code in InitializeComponent
will execute during the designer view, and technically you can update most styles directly here, but it's advised to use the GUI form builder to make any changes against this file
Further Reading: Set Default Cell Styles and Data Formats for the Windows Forms DataGridView Control Using the Designer