Code

#USING System.Drawing

#USING System.Windows.Forms

FUNCTION Start() AS VOID

   Application.Run(TVForm{})

   RETURN

CLASS MyTreeView INHERIT TreeView

PROTECTED 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

END CLASS

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

END CLASS

 

 Print  
Copyright 2012 GrafX Software DevelopmentTerms Of UsePrivacy Statement     Login