Question : Changing  a backcolor of a row in datagridview paints the entire grid+vb.net 2005 windows programming

Hi,
This is a very strange thing as soon I change backcolor of a dg row I can see the entire grid being painted this is a serious overhead in performance.Any suggestions I have setting backcolor on cell formatting event

  Public Sub SortingDgRowFormatting(ByVal dg As DataGridView)
        'This is to retain the formatting of the datagridview after sorting.As sorting of a dagridview column resets the grid
        Dim i As Integer

        For i = 0 To dg.Rows.Count - 1
            If Not IsDBNull(dg.Rows(i).Cells(0).Value) = True Then
                If dg.Rows(i).Cells(0).Value = True Then
                    dg.Rows(i).DefaultCellStyle.BackColor = System.Drawing.SystemColors.InactiveCaptionText
                Else
                    dg.Rows(i).DefaultCellStyle.BackColor = Color.White
                End If
            End If
        Next

Any suggestions?

    End Sub

Answer : Changing  a backcolor of a row in datagridview paints the entire grid+vb.net 2005 windows programming

Try this way
1:
2:
3:
4:
5:
6:
7:
        For Each row As DataGridViewRow In Me.DataGridView1.Rows
            If row.Cells(0).Value IsNot DBNull.Value AndAlso Boolean.Parse(row.Cells(0).Value) = True Then
                row.DefaultCellStyle.BackColor = System.Drawing.SystemColors.InactiveCaptionText
            Else
                row.DefaultCellStyle.ForeColor = Color.White
            End If
        Next
Random Solutions  
 
programming4us programming4us