I'm, trying to color the rows and columns after importing the excel sheet into datagridview.
Rows (A1, A2, A3, A4, A5, A6) should be highlighted in red. (maximum row count is 35)
Columns (Fields, Record 1, Record 2, Record 3, Record 4, Record 5, Record 6, Record 7) should be highlighted in orange. (columns count is not fixed, will be different each time).
dataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.Orange; dataGridView1.RowHeadersDefaultCellStyle.BackColor = Color.Red;
But above code color the unwanted area. How to resolve this.
(colored area in the attached picture should be in white and arrow pointed area should consider the colorings.)
You need to set the default row color and alternate row color styles.
https://learn.microsoft.com/en-us/dotnet/desktop/winforms/controls/how-to-set-alternating-row-styles-for-the-windows-forms-datagridview-control?view=netframeworkdesktop-4.8