Public Control cmdAction(0) As CommandButton Begin
    Caption = "&Close"
    Default = True
    Cancel = True
End Control

Public Control cmdAction(1) As CommandButton Begin
    Caption = "&Add"
    Left = 1200
End Control

Public Control cmdAction(2) As CommandButton Begin
    Caption = "Remo&ve"
    Left = 2400
End Control

Public Control cmdAction(3) As CommandButton Begin
    Caption = "&Properties..."
    Left = 3600
End Control


Private Sub LoadControls Begin
    Source.WriteTo Me
    EnableActions
End Sub


Private Sub EnableActions Begin
    cmdAction(0).Enabled = Not IsBusy
    cmdAction(1).Enabled = Not IsBusy
    cmdAction(2).Enabled = Not IsBusy And Not lvwItem.SelectedItem Is Nothing
    cmdAction(3).Enabled = Not IsBusy And Not lvwItem.SelectedItem Is Nothing

    EnableControls
End Sub

Private Sub EnableControls Begin
    lvwItem.Enabled = Not IsBusy 
End Sub


Public WithEvents Set Source As $__BASECLASS$

Public IsReadOnly As Boolean := False Begin
  Let:
    EnableActions
End Property

Public Sub $__BASECLASS$_Refresh Begin
    LoadControls
End Sub

Private Sub cmdAction_Click(Index As Integer) Begin
    Dim anItem As $__BASECLASSITEMCLASS$

    Select Case Index
        Case 0  ' OK
            Unload Me

        Case 1  ' Add
            Set anItem = New $__BASECLASSITEMCLASS$
            With anItem
                .Key = Source.GetMaxKey() + 1
               ' ...
            End With
            Source.Add anItem, "K" & anItem.Key            
            LoadControls

        Case 2  ' Remove
            If Not lvwItem.SelectedItem Is Nothing Then            
                Source.Remove lvwItem.SelectedItem.Key
                LoadControls
            End If

        Case 3  ' Properties
            If Not lvwItem.SelectedItem Is Nothing Then
                Stop
               '<viewer-form for class>.Edit Source(lvwItem.SelectedItem.Key), vbModeless
               '<viewer-form for class>.IsReadOnly = IsReadOnly
                LoadControls
            End If

    End Select
End Sub

Public State As Integer Begin
  Let:
    EnableActions
End Property

Public Function IsBusy() As Boolean := (State = mintStateBusy)

Declarations
    Private Const mintStateIdle = 1
    Private Const mintStateBusy = 2
End Declarations

Private Sub lvwItem_ColumnClick(ByVal ColumnHeader As ComctlLib.ColumnHeader) Begin
    lvwItem.Sorted = True
    lvwItem.SortKey = ColumnHeader.Index - 1
End Sub

Private Sub lvwItem_DblClick() Begin
    cmdAction_Click 3
End Sub

Private Sub lvwItem_Click() Begin
    EnableActions
End Sub

Private Sub Form_Activate() Begin
    LoadControls
End Sub

Private Sub Form_Resize() Begin
    If Not MDIChild Then
        lvwItem.Width = Me.Width - lvwItem.Left * 2
        lvwItem.Height = Me.Height - lvwItem.Top * 4
        lblItem.Top = lvwItem.Top + lvwItem.Height + lblItem.Height
        lblItem.Width = lvwItem.Width
    End If
End Sub

Private Sub Form_Load() Begin
    State = mintStateIdle
End Sub


Public Function Edit(ByRef EditSource As $__BASECLASS$, Optional ByVal intShowMode As Integer = vbModal) As Boolean Begin

    Set Source = EditSource
    Source.WriteTo Me

    Show intShowMode

    Edit = True
   
End Function



 

