Vulcan.NET Code Examples

For a screen shot of the code below running, please click here.

 

Vulcan.NET  TreeView Example
REFERENCES "System.Drawing"
REFERENCES "System.Windows.Forms"

USING       System.Drawing
USING       System.Windows.Forms

FUNCTION Start() AS VOID

    Application.Run(TVForm{})

    RETURN

CLASS MyTreeView INHERIT TreeView

METHOD OnBeforeExpand( eventArgs AS TreeViewCancelEventArgs ) AS VOID CLASS MyTreeView
    SUPER:OnBeforeExpand(eventArgs)

    IF ! MessageBox.Show("Expand?","TV Example",MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes
        eventArgs:cancel := TRUE
    ENDIF

    RETURN

CLASS TVForm INHERIT Form
    PROTECT tv AS MyTreeView

CONSTRUCTOR() CLASS TVForm
    SUPER()

    SELF:Size := Size{330,260}

    SELF:BuildTV()

    SELF:PopulateTV()

    SELF:Text := "Treeview Example"

    SELF:CenterToScreen()

    RETURN

METHOD BuildTV() AS VOID CLASS TVForm

    SELF:tv := MyTreeView{}
    SELF:tv:Size := Size{300,200}
    SELF:tv:Location := Point{10,10}

    SELF:Controls:Add(SELF:tv)

    RETURN

METHOD PopulateTV() AS VOID CLASS TVForm
    LOCAL oNodes AS TreeNodeCollection
    LOCAL oRoot AS TreeNode
    LOCAL oSub AS TreeNode
    LOCAL ItemName AS STRING
    LOCAL OldCursor AS Cursor
    LOCAL i AS DWORD
    LOCAL j AS DWORD

    OldCursor := Cursor.Current 
    Cursor.Current := Cursors.WaitCursor     

    SELF:tv:BeginUpdate()

    SELF:tv:Nodes:Clear()

    FOR i := 1U UPTO 100U
        ItemName := "Item " + NTrim(i)
        oRoot := TreeNode{ItemName,0,0}
        SELF:tv:Nodes:Add(oRoot)

        oNodes := oRoot:Nodes
        FOR j := 1U UPTO 5U
            oSub := TreeNode{ ItemName+" - subitem "+NTrim(j), 1, 1 }
            oNodes:Add(oSub)
        NEXT
    NEXT

    SELF:tv:EndUpdate()

    Cursor.Current := OldCursor         

    RETURN