Setting ErrorProvider text on an 'invisible' control

I stumbled on this by mistake. I had a case where I was setting ErrorProviders text (calling SetError and passing in the control with text)  on a controls whose Visible property was set to True at runtime.

One would think you'd get an exception, but you do not.  The error provider is happy in this case.  So, as a work around I show a dialog if the control is not visible.

I know, why is a validated control not visible, long story.

 

PrivateSub SetCboSesErrorProviderValue(ByVal session As String)

If Me.IsConference AndAlso Me.LeaderIsAssignedToSession(session) Then

    ErrorProvider.SetError(Me.cboSes, "Leader is already assigned to session " & session & ".")

    If Not Me.cboSes.Visible Then

        AlertBox.Show(Me, Me._leaderName.Trim() & " has already been assigned as a leader to this event.", _

            "Leader Already Assigned to Event", Windows.Forms.MessageBoxButtons.OK, _

            Windows.Forms.MessageBoxIcon.Error)

    End If

Else

    ErrorProvider.SetError(Me.cboSes, "")

End If

End Sub ' SetCboSesErrorProviderValue

 

No Comments