Winforms Coding Patterns - Basic form pattern

This is the basic pattern for creating new WinForms forms

Related Articles

... and you 'll find more on the NET Development Menu

Public Class Transfer
    Dim mstrDocNumber As String
    Enum FormStateType
        Clean
        Populated
    End Enum
    Private _FormState As FormStateType
    Public Property FormState() As FormStateType
        Get
            Return _FormState
        End Get
        Set(ByVal value As FormStateType)
            _FormState = value
            Select Case value
                Case FormStateType.Clean
                    'blank all the fields
 
 
                    'disable all the fields
                Case FormStateType.Populated
                    'enable fields
 
            End Select
        End Set
    End Property
 
 
    Sub New(strDocNumber As String)
 
        ' This call is required by the designer.
        InitializeComponent()
 
        ' Add any initialization after the InitializeComponent() call.
        mstrDocNumber = strDocNumber
    End Sub
 
    Private Sub Transfer_FormClosed(sender As Object, e As FormClosedEventArgs) Handles Me.FormClosed
        Me.Dispose()
        GC.Collect()
    End Sub
 
    Private Sub Transfer_Load(sender As Object, e As EventArgs) Handles Me.Load
        Dim strError As String = ""
        Try
 
            SetupGrid()
            BindGrid()
            Populate
        Catch ex As Exception
            ErrorHandler.globalErrorHandler(ex, strError, App.AppName, App.UserName, True)
        End Try
 
    End Sub
    Sub SetupGrid()
        Dim strError As String = ""
        Try
            Dim oTelerikGrid As New TelerikGrid
 
            'add new columns by type and name to the grid...verified in SQL server
            Me.RadGridView1.Columns.Add(oTelerikGrid.createGridViewTextBoxColumn("", "RowID", 11, 200, False, True))
 
            'set the grid properties
            Me.RadGridView1.EnableGrouping = False
            Me.RadGridView1.AllowAddNewRow = False
            Me.RadGridView1.AllowDeleteRow = False
            Me.RadGridView1.AllowEditRow = False
            Me.RadGridView1.EnableFiltering = True
            Me.RadGridView1.MasterTemplate.EnableSorting = True
 
        Catch ex As Exception
            ErrorHandler.globalErrorHandler(ex, strError, App.AppName, App.UserName, True)
        End Try
    End Sub
    Sub BindGrid()
        Dim strError As String = ""
        Try
 
            RadGridView1.DataSource = Nothing 'data access code
 
        Catch ex As Exception
            ErrorHandler.globalErrorHandler(ex, strError, App.AppName, App.UserName, True)
        End Try
 
    End Sub
    Sub Populate()
        If mstrDocNumber.Trim > "" Then
            'populate the form
 
 
 
            'set the form state
            FormState = FormStateType.Populated
        Else
            'set the form state to clean, which will clear it
            FormState = FormStateType.Clean
        End If
    End Sub
End Class

 

 

 


RealWorldCode gives developers practical, real‑world solutions with clean, working code — no fluff, no theory, just answers.
Links
Home
Knowledge Areas
Sitemap
Contact
Et cetera
Privacy Policy
Terms and Conditions
Cookie Preferences