Welcome / Home
Understanding My PC
Software Downloads
VB.NET
JAVA
C#.NET
RPG
SQL
Software Engineering
Networking
Communications
Security
Internet Links
Contact Us

How to Code a Treeview


How to Code a Treeview

 

TreeViews are a great Selection Tool.  What you need to understand with the .NET Teeview is how it stores data using a hierarchical structure.  Thus, we build each level with a key value.   Notice how we used an Array List to store and retrieve an additional  number.  We only included the routines needed for the operation of the TreeView.  Notice how we can parse out the information we need from the TreeView in the double_click event.  We use HEADLINE Scripting with lowercase prefixes for most objects.  We also use acronyms for field names  (AccountNumber=ACTNBR).   Please pardon the formatting from the HTML editor.  Indentations were lost, and it selected some funky fonts and colors.
 
Copyrighted by CompuCranks.com (2006)

Private  trvNUMBER As New ArrayList

'****************************************************************************************
Private Sub prcBUILD_GRADEABLE_TREVIEW()
'****************************************************************************************
   Dim wrkCRSCDE As String = "", C As Windows.Forms.TreeNode = Nothing, G As Windows.Forms.TreeNode = Nothing
   Call prcSQLGDM("GRADEABLES")
   trvNUMBER.Clear()
   trvGRADEABLE.Nodes.Clear()
   trvGRADEABLE.BeginUpdate()
  Do While rdrGDM.Read()
     If wrkCRSCDE <> CStr(rdrGDM.Item("crmCRSCDE")) Then
         C = New Windows.Forms.TreeNode(CStr(rdrGDM.Item("crmCRSCDE")) & " " & CStr(rdrGDM.Item("crmCRSNME")), 0, 1)
         trvGRADEABLE.Nodes.Add(C)
         wrkCRSCDE = CStr(rdrGDM.Item("crmCRSCDE"))
     End If
    G = New Windows.Forms.TreeNode(CStr(rdrGDM.Item("gdmDESCPT")), 2, 2)
    C.Nodes.Add(G) : trvNUMBER.Add(rdrGDM.Item("gdmGRDNBR"))
  Loop
  trvGRADEABLE.SelectedNode = trvGRADEABLE.Nodes(0)
  trvGRADEABLE.SelectedNode.ExpandAll()
  trvGRADEABLE.EndUpdate()
End Sub
'****************************************************************************************
Private Sub trvGRADEABLE_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles trvGRADEABLE.DoubleClick
'****************************************************************************************
  If trvGRADEABLE.SelectedNode.Level > 0 Then
     hldSTDGRD = trvGRADEABLE.SelectedNode.Text
     lblSTDGRD.Text = trvGRADEABLE.SelectedNode.Text
     hldGRDNBR = CLng(trvNUMBER(trvGRADEABLE.SelectedNode.Index))
     Call prcSQLGDM("GRADEABLE")
     If rdrGDM.Read() Then
        tbxMAXPTS.Text = CStr(rdrGDM.Item("gdmMAXPTS"))
     End If
     Call prcBUILD_STUDENT_GRADE_LIST()
  End If
End Sub