Site Search:
Sign in | Join | Help

This Blog

Syndication

VB.NET

Notes, Tricks and Tips on VB.NET

Code to Populate a FormObjects Collection

Code for the object 

 Public Class formObject
    Public Name As String
    Public Type As String
    Public Control As Control
    Public Tag As String = ""


    Sub New(ByVal name As String, ByVal type As String, ByVal control As Control, ByVal tag As String)
        Me.Name = name
        Me.Type = type
        Me.Control = control


        If Not String.IsNullOrEmpty(tag) Then
            Me.Tag = tag
        End If
    End Sub
End Class
 

'at the form level:
Dim formObjects As New List(Of formObject)
Dim bDirty As Boolean




     Sub populateFormObjectsCollection()
        Dim o As formObject
        'load the form fields into a collection



        For Each c As Control In Me.Controls
            Select Case Microsoft.VisualBasic.Left(c.Name, 3).ToUpper
                Case "TXT", "DDL", "BTN"
                    o = New formObject(c.Name, Microsoft.VisualBasic.Left(c.Name, 3).ToUpper, c, c.Tag)
                    formObjects.Add(o)
            End Select
        Next



For Each o In formObjects
    Select Case o.Tag.ToUpper
        Case "KEY"
        Case "NOENABLE"
        Case Else
            AddHandler o.Control.TextChanged, AddressOf TextChangedEvent
            AddHandler o.Control.Validating, AddressOf ValidatingEvent
    End Select
Next



    End Sub

Code for the event handler

 Private Sub TextChangedEvent(ByVal sender As Object, ByVal e As System.EventArgs)
    Select Case Me.FormState
        Case formStateType.clean, formStateType.populated
            bDirty = True
            Me.txtStatus1.Text = "Dirty"
    End Select
End Sub
Private Sub ValidatingEvent(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)
    If bDirty Then


        'the user has changed the value in a field other than Product Number


        Select Case Me.FormState
            Case formStateType.loading
                Exit Sub
            Case formStateType.clean
                globalMessageBox("Please choose a Project first")


            Case formStateType.populated
                setFormState(formStateType.dirty)
            Case formStateType.dirty


        End Select


        bDirty = False
    End If
End Sub

Comments

 

VB.NET said:

Here is a standard process to use to code a standard VB.NET 'card' form. It helps to have a checklist

March 27, 2009 6:33 PM

Leave a Comment

(required)  
(optional)
(required)  
Add

About Steve Gray

Steve is a seasoned (translate: old) developer in VB and ASP.NET. He spends most of his time in Dynamics GP, writing custom mods for consulting firms. Crystal reports, eConnect, VS Tools for Dynamics... anything that comes along.