I have tested your code and the line responsible for the behaviour you are describing is this.dataGridView1.Invalidate(rtHeader);
Thus you have two solutions:
- Deleting the aforementioned line.
- Or putting the rectanges in the cells (in the first row, would be fine), rather than in the headers.