Windows Develop Bookmark and Share   
 index > Windows Forms General > Using ErrorProvider for multiple text boxes
 

Using ErrorProvider for multiple text boxes

I have a sample program that takes in change (money) amounts and converts them into the largest denominations possible (I teach VB.NET at a college and I made it up for my students to do).  I am using the error provider to validate the input in each text box.  Unfortunately, I have to duplicate the code for the validating event for each text box and change the control name to the particular text box.  Is there any way to place this code in a procedure and let it handle the validating events for all of the text boxes?  I want to leave option strict on so it won't allow me to late bind.  Any info you can provide would be greatly appreciated.

Paul Norrod.

Here is my current code for the validating event for one of the text boxes (I can't retain my tabs in this thing - sorry):

Private Sub txtQuartersIn_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtQuartersIn.Validating

        If Not IsNumeric(txtQuartersIn.Text) Then
            erpValidateInput.SetError(txtQuartersIn, "A non-numeric value was entered - Please correct")
            e.Cancel = True
        Else
            If CDec(txtQuartersIn.Text) < 0 Or CDec(txtQuartersIn.Text) > 10000 Then
                erpValidateInput.SetError(txtQuartersIn, "The value entered must be between 1 and 10,000 - Please correct")
                e.Cancel = True
            Else
                If CDec(txtQuartersIn.Text) <> CInt(txtQuartersIn.Text) Then
                    erpValidateInput.SetError(txtQuartersIn, "Decimal values are not permitted - Please correct")
                    e.Cancel = True
                Else
                    erpValidateInput.SetError(txtQuartersIn, "")
                End If
            End If
        End If

 End Sub
MigrationUser 1  Wednesday, February 19, 2003 9:11 PM
using vb.net you hook the validating events for one or more textboxes to a single event handler by appending the handles statement e.g.

Private Sub Money_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txt1.Validating , txt1.Validating ,txt2.Validating 


assuming you all text boxes exists, you then can verify which control raise the event by comparing the sender parameter


reagrds
erymuzuan mustapa
MigrationUser 1  Wednesday, February 19, 2003 9:35 PM

You can use google to search for other answers

Custom Search

More Threads

• How to display properties in different colors on a PropertyGrid
• how to create a custom toolbox in c#
• Report Question
• DataGridView Combobox auto drop down?
• How to install an application in an machine?
• BUG: ContextMenu Shortcut (Accelerator) Problem
• CrystalDecidions.CrystalReports.Engine HELP
• Custom Toolbox with User Controls
• Use Microsoft Office Outlook in Application
• Writing text mirrored....