Use ErrorProvider with Custom Control?
Use ErrorProvider with Custom Control?
Use ErrorProvider with Custom Control?
Use ErrorProvider with Custom Control?
Use ErrorProvider with Custom Control?
Use ErrorProvider with Custom Control? Use ErrorProvider with Custom Control? Use ErrorProvider with Custom Control? Use ErrorProvider with Custom Control? Use ErrorProvider with Custom Control? Use ErrorProvider with Custom Control? Use ErrorProvider with Custom Control? Use ErrorProvider with Custom Control?
Use ErrorProvider with Custom Control? Use ErrorProvider with Custom Control?
Use ErrorProvider with Custom Control?
Go Back  Xtreme Visual Basic Talk > > > Use ErrorProvider with Custom Control?


Reply
 
Thread Tools Display Modes
  #1  
Old 05-23-2013, 09:04 AM
RM33 RM33 is offline
Newcomer
 
Join Date: Jan 2013
Posts: 20
Default Use ErrorProvider with Custom Control?


I am using VB 2010.

This is my goal. I have made a custom control textbox. Management likes it when we use the ErrorProvider because it traps the user in the textbox until they enter the right stuff. Also, there is a blinking exclamation point next to the textbox that they seem to like.

My question is, how can I combine the ErrorProvider with a custom control?
Reply With Quote
  #2  
Old 05-23-2013, 09:44 AM
DrPunk's Avatar
DrPunkUse ErrorProvider with Custom Control? DrPunk is offline
Senior Contributor

* Expert *
 
Join Date: Apr 2003
Location: Never where I want to be
Posts: 1,403
Default

I've never used an ErrorProvider before, but I think this is how you'd incorporate one in a custom control...
Code:
Public Class MyTextBox
    Inherits TextBox

    ' Having myError protected would allow other controls inheritted off this
    ' to set up different properties for the ErrorProvider in its own Sub New
    ' if you wanted to.
    Protected myError As New ErrorProvider

    Sub New()
        myError.SetIconAlignment(Me, ErrorIconAlignment.MiddleRight)
        myError.SetIconPadding(Me, 2)
        myError.BlinkRate = 1000
        myError.BlinkStyle = System.Windows.Forms.ErrorBlinkStyle.AlwaysBlink
    End Sub

    ' Normally you'd act on the Validate event of the control in the form, but we want to
    ' validate here so you override the OnValidating method.
    Protected Overrides Sub OnValidating(ByVal e As System.ComponentModel.CancelEventArgs)
        MyBase.OnValidating(e)

        If IsValid() Then
            myError.SetError(Me, String.Empty)
        Else
            myError.SetError(Me, "Not valid")
            ' The cancel stops the focus moving to the next control
            e.Cancel = True
        End If
    End Sub

    ' You need to have some function to validate the contents of the text. Having it overridable means
    ' that you could inherit this textbox and just change how its validated rather than adding an
    ' ErrorProvider to every one of you own created textboxes.
    Protected Overridable Function IsValid() As Boolean
        ' Lame validation check for the example
        If Me.Text.ToUpper = "VALID" Then
            Return True
        Else
            Return False
        End If
    End Function
End Class
Seems to work, but I can't confirm that 100% cos I'm not totally sure what it's supposed to do.
__________________
There are no computers in heaven!

Last edited by DrPunk; 05-23-2013 at 10:02 AM.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Use ErrorProvider with Custom Control?
Use ErrorProvider with Custom Control?
Use ErrorProvider with Custom Control? Use ErrorProvider with Custom Control?
Use ErrorProvider with Custom Control?
Use ErrorProvider with Custom Control?
Use ErrorProvider with Custom Control? Use ErrorProvider with Custom Control? Use ErrorProvider with Custom Control? Use ErrorProvider with Custom Control? Use ErrorProvider with Custom Control? Use ErrorProvider with Custom Control? Use ErrorProvider with Custom Control?
Use ErrorProvider with Custom Control?
Use ErrorProvider with Custom Control?
 
Use ErrorProvider with Custom Control?
Use ErrorProvider with Custom Control?
 
-->