You might try the following solution so that you do not have to set the selection background color on each new screen.
- Create a custom DataGridView to be used by your application.
- In the constructor, you can handle the DataGridView's ColumnStateChanged event and reset the HeaderCell's Style to the default background value:
e.g:
public class DataGridViewCustom : DataGridView
{
public DataGridViewSearch() : base()
{
InitializeComponent();
this.ColumnStateChanged += DataGridViewCustom_ColumnStateChanged;
}
private void DataGridViewCustom_ColumnStateChanged(object sender, DataGridViewColumnStateChangedEventArgs e)
{
DataGridView dataGridView = (DataGridView)sender;
//Only update for full row selection mode.
if (dataGridView.SelectionMode == DataGridViewSelectionMode.FullRowSelect)
{
e.Column.HeaderCell.Style.SelectionBackColor = dataGridView.ColumnHeadersDefaultCellStyle.BackColor;
}
}
}