I have a TabControl which contains 2 DataGridViews on separate tabs. Both of these are populated based on the value of the selected row on a third DGV, which is outside the TabControl.
I am trying to colour the left-hand column of one of the DGVs in blue, which is working fine provided the Page containing that DGV is currently visible. If it is not currently visible then the colour is not changed. The code I am using to change cell colour is
foreach (DataGridViewRow row in this.dgvInformation.Rows)
{
DataGridViewCellStyle blueStyle = new DataGridViewCellStyle();
blueStyle.Font = new Font("Microsoft Sans Serif", 8.25F, FontStyle.Regular);
blueStyle.BackColor = Color.LightBlue;
row.Cells["InfoType"].Style = blueStyle;
}
I have stepped through the code and it takes an identical path whether the DGV is visible or not, but the cell colour is only changed when it is visible.
Is there a reason why a DGV can’t have it’s cell colour changed if it is not currently displayed?
Many thanks
[Apologies for answering my own question here – the credit belongs to Shane C I just don’t like to leave unanswered questions!]
The fix is to add the cell colouring code to the VisibleChanged event of the DataGridView, and also to the Sorted event if sorting is allowed