Hi All,

new to this quality forum. Beginner in VB hoping to become a professional, hopefully one day ;)

got this code from googling:

Private Sub DataGridView1_CellValueChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged

        If e.RowIndex <> -1 AndAlso e.ColumnIndex = Column1.Index Then
            Dim cell As DataGridViewComboBoxCell = DataGridView1(e.ColumnIndex, e.RowIndex)
            Dim retrievedValue As Boolean = cell.Value 'DataGridView1(e.ColumnIndex, e.RowIndex).Value

            If retrievedValue = True Then
                cell.Style.BackColor = Color.Green
            Else
                If retrievedValue = False Then
                    cell.Style.BackColor = Color.Red
                End If
            End If
        End If


    End Sub

completely understand what it does, when the cell value is changed the color of the cell changes according to the value selected.

Now, how would i change this code so that it works when the form loads? so cells show the color when the form loads. red for unpaid and green for paid.

cheers

Loop through all records in your datagridview - after populating the dgv and not on form load necessarily - and set the color as per your criteria.

Have you tried anything yet?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.