Datagridview not showing colors until a column is clicked

  • Thread starter Thread starter Hugh Self Taught
  • Start date Start date
H

Hugh Self Taught

Guest
Hi Clever people,

I have a datagridview on my form which I set the datasource to a datatable & the data appears fine. I then set the different columns to have their own color & I set the columns to specific widths. I've tried all sorts of timing & refresh statements etc to no avail on the colors. I have to click on a column header changing the sort then the colors apply so I have to click a 2nd time to get the sort as it should be. Am I maybe missing an imports or what else could be the cause?

Here is the code I'm using. Any advice really appreciated

Using cmd = New SqlCommand("stpHistEnquiryBall", conn)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@Competitor", index)
dr = cmd.ExecuteReader()

bt.Load(dr)

End Using 'cmd



dgvBall.DataSource = bt
dr.Close()

Dim Bcolwidth0 As DataGridViewColumn = dgvBall.Columns(0)
Bcolwidth0.Width = 160
Dim Bcolwidth1 As DataGridViewColumn = dgvBall.Columns(1)
Bcolwidth1.Width = 250
Dim Bcolwidth2 As DataGridViewColumn = dgvBall.Columns(2)
Bcolwidth2.Width = 80
Dim Bcolwidth3 As DataGridViewColumn = dgvBall.Columns(3)
Bcolwidth3.Width = 260
Dim Bcolwidth4 As DataGridViewColumn = dgvBall.Columns(4)
Bcolwidth4.Width = 70
dgvBall.Columns(0).CellTemplate.Style.BackColor = Drawing.Color.LightGreen
dgvBall.Columns(1).CellTemplate.Style.BackColor = Drawing.Color.Bisque
dgvBall.Columns(2).CellTemplate.Style.BackColor = Drawing.Color.LightCoral
dgvBall.Columns(3).CellTemplate.Style.BackColor = Drawing.Color.Aqua
dgvBall.Columns(4).CellTemplate.Style.BackColor = Drawing.Color.SandyBrown

Continue reading...
 
Back
Top