What Events fire when a TabPage is loaded?

I'm having a problem with a two of TabPages (TB) and not sure how to resolve the issue. First, the problem is that I have a DataGridView (DGV) on each of the TB's that when loaded they will show color in specific cells based on certain criteria. This functionality occurs as the result of a call from within the "Enter" Event of each TabPage. It's the last line of code executed in each Event. When the TB loads, the routine executes and does what it should, however, the specific cells are not colored as they should be. The weird thing is that when I click on another TB and then click on the previous TB, everything works fine. So, it seems on initial load that this functionality isn't working but once I toggle the TB's...they both work fine.

Here is the routine that does the coloring:

    Private Sub FormatGridRepeat()
        Try
            Dim rIDX As Integer = 0
            Dim maxError As Decimal = 0
            Dim blnFirstTime As Boolean = True

            EH.ErrorMessage = String.Empty

            If blnFormatRepeatabilityGrid Then
                For Each row As DataGridViewRow In dgvRepeatability.Rows
                    If Not stcDefaultValues.repeatabilityMIN Is Nothing And Not stcDefaultValues.repeatabilityMAX Is Nothing Then
                        If CInt(row.Cells(2).Value) <> 0 Then
                            If blnFirstTime Then
                                blnFirstTime = False
                                If IsNumeric(row.Cells(4).Value) Then
                                    maxError = CDec(row.Cells(4).Value)
                                End If
                            End If

                            If row.Cells(4).Value.ToString.Length > 0 Then
                                If IsNumeric(row.Cells(4).Value) Then
                                    If CDec(row.Cells(4).Value) >= maxError Then
                                        maxError = CDec(row.Cells(4).Value)
                                        rIDX = row.Index
                                    End If
                                End If
                            End If

                            If IsNumeric(row.Cells(4).Value) Then
                                If (CDec(row.Cells(4).Value) < CDec(stcDefaultValues.repeatabilityMIN)) Or (CDec(row.Cells(4).Value) > CDec(stcDefaultValues.repeatabilityMAX)) Then
                                    dgvRepeatability.Rows(row.Index).Cells(4).Style.BackColor = Color.Salmon
                                End If
                            End If
                        End If
                    End If
                Next

                If CDec(dgvRepeatability.Rows(rIDX).Cells(2).Value) <> 0 Then
                    If (CDec(maxError) < CDec(stcDefaultValues.repeatabilityMIN)) Or (CDec(maxError) > CDec(stcDefaultValues.repeatabilityMAX)) Then
                        dgvRepeatability.Rows(rIDX).Cells(4).Style.BackColor = Color.Salmon
                    Else
                        dgvRepeatability.Rows(rIDX).Cells(4).Style.BackColor = Color.PaleGreen
                    End If
                End If
            End If

            dgvRepeatability.ClearSelection()

        Catch ex As Exception
            EH.ErrorMessage = "frmCalibration_3/FormatGridRepeat() - " & ex.Message & "...Contact Engineering!" & "~E"
        End Try
    End Sub

Open in new window


Is there another Event that fires after the "Enter" Event that I could perhaps insert this call?

Thanks!
BlakeMcKennaAsked:
Who is Participating?
 
Éric MoreauSenior .Net ConsultantCommented:
I just made a quick test and I really think that the SelectedIndexChange event would work.

My test was to check if the datagridview was visible. In the Selected event it was not. In the SelectedIndexChange, it was.
0
 
Éric MoreauSenior .Net ConsultantCommented:
Have you tried calling this method from the Selected event of the TabControl. Sometimes, controls are not reacting properly when they are not shown (and the tabpages that are not active are not shown).
0
 
BlakeMcKennaAuthor Commented:
Eric,

I ran it through the debugger and the "Selected" Event actually fired before the "Enter" Event. It executed the routine but it had no effect.

    Private Sub tabTests_Selected(sender As Object, e As TabControlEventArgs) Handles tabTests.Selected
        'Debug.Print("tabTests_Selected")

        Try
            EH.ErrorMessage = String.Empty

            Select Case e.TabPage.Name
                Case "tabCreepTest"
                    FormatGridCreep()
                Case "tabRepeatabilityTest"
                    FormatGridRepeat()
            End Select

        Catch ex As Exception
            EH.ErrorMessage = "frmCalibration_3/tabTests_Selected() - " & ex.Message & "...Contact Engineering!" & "~E"
        End Try

        EH.ProcessMessages(Me, sbr, EH.ErrorMessage)
    End Sub

Open in new window

0
 
BlakeMcKennaAuthor Commented:
Eric,

That did it...works great now!

Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.