I have a DataGridView populated when entering a Tab. I need to loop through the DataGridView after the Datasource is assigned to apply formatting, however the method I'm using to format the grid is firing multiple times. I've tried a few methods like .DataBindingComplete and .Sorted but the results are the same. I read a post where someone used DataGridViewCellFormattingEventArgs but I didn't understand how to handle this. I just need to find a method that reliably fires only once after the DGV is populated to do the loop.

I had to sanitize this pretty heavily so I apologize for any typos:

VB.NET Code:
  1. Private Sub Tab3Enter(sender, e) Handles TabPage3.Enter
  2.         Call ProjTab()
  3. End Sub
  4.  
  5. Dim dt As New
  6.  
  7. Public Sub ProjTab()
  8.  
  9.         'DataGridView 3
  10.         dt.Clear()
  11.  
  12.         Dim sqConQC As New SqlClient.SqlConnection(DATABASE)
  13.         Dim sqCmdQC As New SqlClient.SqlCommand
  14.  
  15.         sqCmdQC.Connection = sqConQC            'create the DB connection
  16.         sqConQC.Open()                        'open the connection
  17.         Dim Adapter As New SqlDataAdapter
  18.  
  19.  
  20.         sql = "SELECT * FROM QuoteView WHERE DateModified >= '2019-01-01' AND Accepted = 1 AND (Released = 1 AND SONO IS NULL) OR ReleaseMod = 1 ORDER BY QuoteNo DESC"
  21.         Adapter.SelectCommand = New SqlCommand(sql, sqConQC)
  22.         Adapter.Fill(dt)
  23.         sqConQC.Close()
  24.  
  25.         Me.DataGridView3.DataSource = dt
  26.  
  27.   End Sub
  28.  
  29.    Private Sub ColorDGV(sender As Object, e As EventArgs) Handles DataGridView1.DataBindingComplete, DataGridView2.DataBindingComplete, DataGridView3.DataBindingComplete
  30.  
  31.         Dim DGV As DataGridView = Nothing
  32.  
  33.         If Me.TabControl1.SelectedTab Is TabPage1 Then
  34.             DGV = Me.DataGridView1
  35.         ElseIf Me.TabControl1.SelectedTab Is TabPage2 Then
  36.             DGV = Me.DataGridView2
  37.         ElseIf Me.TabControl1.SelectedTab Is TabPage3 Then
  38.             DGV = Me.DataGridView3
  39.         End If
  40.  
  41.         If DGV.IsHandleCreated Then
  42.  
  43.             Me.ProgressBar1.Visible = True
  44.             Dim i As Integer = DGV.Rows.Count
  45.  
  46.             If i > 0 Then
  47.  
  48.                 ProgressBar1.Maximum = i
  49.                 Dim c As Integer = 0
  50.                 For Each row As DataGridViewRow In DGV.Rows
  51.                  
  52.                    'do lots of stuff
  53.  
  54.                     If ProgressBar1.Value <> ProgressBar1.Maximum Then
  55.                         c = c + 1
  56.                     End If
  57.                     ProgressBar1.Value = c
  58.                 Next
  59.             End If
  60.         End If
  61.         Me.ProgressBar1.Visible = False
  62.  
  63.     End Sub