[RESOLVED] DataGridView first row
On opening a form (and the DataGridView in it), I try to set the back color of my entire first row as follows :
DataGridView1.Rows(0).SelectionBackColor = Color.BlanchedAlmond
However, this seems not to be correct. I have tried several alternatives, but no luck so far.
Anyone who knows the proper coding ?
Re: DataGridView first row
When changing the color of a row, you actually have to change the color of each cell in the row.
Here is how to change the default back color of each cell in a row:
Code:
DataGridView1.Rows(0).DefaultCellStyle.BackColor = Color.BlanchedAlmond
Here is another way... Enumerate through each cell in a row, and change the back color one by one:
Code:
For Each dgvc as DataGridViewCell In DataGridView1.Rows(0).Cells
dgvc.Style.BackColor = Color.BlanchedAlmond
Next
Re: DataGridView first row
Dear MotoX646,
Thanks but neither of these two solutions is working for me. The first one I already tried myself before posting this thread.
But maybe I am not properly formulating my problem.
What I really want to do, is to get rid of the blue background color in cell (0,0) whenever I open the Form with the DataGridView in it.
I am already using background colors in combination with MouseEnter, MouseLeave etc. … on my rows, but the blue background for cell (0,0) only disappears when I enter cell/row (0).
I want to be cell (0,0) white from the very start so that my BlanchedAlmond will be the only color in the grid.
I assume your solutions come in prior to VS setting the background color to standard blue (and therefore your solutions are overruled).
Re: DataGridView first row
Ooooh... You must be talking about the "selected cell" that is selected by default. The blue color indicates the cell is selected. In that case, you just want to clear all the selected.
Code:
DataGridView1.ClearSelection()
If you just want to deselect cell(0,0) you can do this:
Code:
DataGridView1.Rows(0).Cells(0).Selected = False
Re: DataGridView first row
That seems to be working ... and it is of course a much easier and more direct approach than what I had in mind.
Thanks !
Re: DataGridView first row
No problem...
If you want to change the selection color of "selected" rows / cells, you can do this:
Code:
DataGridView1.RowsDefaultCellStyle.SelectionBackColor = Color.Red
Or, if you want to change the selection color of a specific "selected" cell, you can do this:
Code:
DataGridView1.Rows(0).Cells(0).Style.SelectionBackColor = Color.Red
That way you can change the default selection color of blue to another color.