0

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

2
Contributors
1
Reply
2
Views
4 Years
Discussion Span
Last Post by adam_k
0

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?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.