Results 1 to 4 of 4

Thread: TreeView Structure Help Needed [RESOLVED]

Threaded View

  1. #1

    Thread Starter
    Fanatic Member JCScoobyRS's Avatar
    Join Date
    Oct 2002
    Location
    Some Mountain in Colorado
    Posts
    677

    TreeView Structure Help Needed [RESOLVED]

    I have a TreeView that is built, at run-time, via drag and drop. I have posted many times regarding how my TreeView structure isn't built the way it's created (See: http://www.vbforums.com/showthread.p...hreadid=235951) There is an attached zip file with 2 pictures to view to see my delimma. To make a long story short, I figured out a way to fix my delimma BUT it might be a little slower than I had hoped for. None the less, it will work and I'm going to do it. Here is my code right now to build the TreeView. It will rebuild ANY TreeView regardless of how many levels the TreeView has. That's the beauty BUT it doesn't put the nodes in the proper order under their parent. Here is the code:

    VB Code:
    1. 'TreeView Functions
    2. '------------------
    3. Public Sub Create_Tree()
    4.     Dim OraSession As OraSession
    5.     Dim OraDatabase As OraDatabase
    6.     Dim OraDynaSet As OraDynaSet
    7.     Dim OraFields As OraFields
    8.     Dim NewNodeKey As Node
    9.     Dim PSCPKEY As String
    10.     Dim txtNewNodeKey As String
    11.     Dim ProNodeCheck As String
    12.     Dim ProNodeKey As String
    13.     ' Create the OraSession Object. The argument to CreateObject is the
    14.     ' name by which theOraSession object is known to the OLE system.
    15.     Set OraSession = CreateObject("OracleInProcServer.XOraSession")
    16.    
    17.     ' Create the OraDatabase Object by opening a
    18.     ' connection to Oracle.
    19.     Set OraDatabase = OraSession.OpenDatabase("QSDB", "QSDB_USER/5star5", 0&)
    20.    
    21.     ' Create the OraDynaset Object.
    22.     Set OraDynaSet = OraDatabase.CreateDynaset("select * from PS where PS_IMKEY = '" & gbtxtPartName & "'", 0&)
    23.     Set OraFields = OraDynaSet.Fields
    24.     'Create Root Node and it's children
    25.     OraDynaSet.MoveFirst
    26.     tvPS.Nodes.Clear
    27.     tvPS.Nodes.Add , , gbtxtPartName & "_PART", gbtxtPartName
    28.     Do While Not OraDynaSet.EOF
    29.         Set NewNodeKey = tvPS.Nodes.Add((gbtxtPartName & "_PART"), tvwChild, gbtxtPartName & "_PART" & "_" & OraFields("PS_CPKEY").Value & "_MAT", OraFields("PS_CPKEY").Value)
    30.         PSCPKEY = OraFields("PS_CPKEY").Value
    31.         txtNewNodeKey = NewNodeKey.Key
    32.         ProNodeCheck = OraFields("PS_CPKEY").Value
    33.         ProNodeKey = NewNodeKey.Key
    34.         Call Check_Node_Pro(ProNodeCheck, ProNodeKey)
    35.         Call Check_Node_Mat(PSCPKEY, txtNewNodeKey) 'Calls function to test a node for children nodes
    36.         OraDynaSet.MoveNext
    37.     Loop
    38.    
    39.     ProNodeCheck = gbtxtPartName
    40.     ProNodeKey = gbtxtPartName & "_PART"
    41.     Call Check_Node_Pro(ProNodeCheck, ProNodeKey)
    42.     Call Select_Expand 'Calls the function used to expand the parent node
    43.     Call Assign_Icons 'Calls the function used to assign all icons to the nodes
    44. End Sub
    45. Private Sub Check_Node_Mat(ByVal PSCPKEY As String, ByVal txtNewNodeKey As String)
    46.     Dim OraSession1 As OraSession
    47.     Dim OraDatabase1 As OraDatabase
    48.     Dim OraDynaSet1 As OraDynaSet
    49.     Dim OraFields1 As OraFields
    50.     Dim NewNodeKey1 As Node
    51.     Dim txtParentNode As String
    52.     Dim PSCPKEY1 As String
    53.     Dim txtNewNodeKey1 As String
    54.     Dim ProNodeCheck As String
    55.     Dim ProNodeKey As String
    56.     Set OraSession1 = CreateObject("OracleInProcServer.XOraSession")
    57.     Set OraDatabase1 = OraSession1.OpenDatabase("QSDB", "QSDB_USER/5star5", 0&)
    58.     Set OraDynaSet1 = OraDatabase1.CreateDynaset("select PS_IMKEY,PS_CPKEY from PS where PS_IMKEY = '" & PSCPKEY & "'", 0&)
    59.     Set OraFields1 = OraDynaSet1.Fields
    60.         If OraFields1.Count = 0 Then 'Checks to see if the node has children nodes
    61.             Exit Sub 'If no children nodes, exit sub
    62.         Else
    63.             OraDynaSet1.MoveFirst 'If children nodes exist, create
    64.             Do While Not OraDynaSet1.EOF
    65.             txtParentNode = tvPS.Nodes(tvPS.Nodes.Count).Parent.Text
    66.             Set NewNodeKey1 = tvPS.Nodes.Add((txtNewNodeKey), tvwChild, txtNewNodeKey & "_" & OraFields1("PS_CPKEY") & "_MAT", OraFields1("PS_CPKEY"))
    67.             PSCPKEY1 = OraFields1("PS_CPKEY")
    68.             txtNewNodeKey1 = NewNodeKey1.Key
    69.             ProNodeCheck = OraFields1("PS_CPKEY").Value
    70.             ProNodeKey = NewNodeKey1.Key
    71.             Call Check_Node_Pro(ProNodeCheck, ProNodeKey)
    72.             Call Check_Child_Node_Mat(PSCPKEY1, txtNewNodeKey1) 'Check new node for children
    73.             OraDynaSet1.MoveNext
    74.             Loop
    75.         End If
    76. End Sub
    77. Private Sub Check_Child_Node_Mat(ByVal PSCPKEY1 As String, ByVal txtNewNodeKey1 As String)
    78.     Dim OraSession2 As OraSession
    79.     Dim OraDatabase2 As OraDatabase
    80.     Dim OraDynaSet2 As OraDynaSet
    81.     Dim OraFields2 As OraFields
    82.     Dim NewNodeKey2 As Node
    83.     Dim txtParentNode1 As String
    84.     Dim PSCPKEY As String
    85.     Dim txtNewNodeKey As String
    86.     Dim ProNodeCheck As String
    87.     Dim ProNodeKey As String
    88.     Set OraSession2 = CreateObject("OracleInProcServer.XOraSession")
    89.     Set OraDatabase2 = OraSession2.OpenDatabase("PKDEMO", "pkdemo/pkdemo", 0&)
    90.     Set OraDynaSet2 = OraDatabase2.CreateDynaset("select PS_IMKEY,PS_CPKEY from PS where PS_IMKEY = '" & PSCPKEY1 & "'", 0&)
    91.     Set OraFields2 = OraDynaSet2.Fields
    92.         If OraFields2.Count = 0 Then 'Checks nodes for children
    93.             Exit Sub 'If no children nodes, exit sub
    94.         Else
    95.             OraDynaSet2.MoveFirst 'If children nodes exist, create
    96.             Do While Not OraDynaSet2.EOF
    97.             txtParentNode1 = tvPS.Nodes(tvPS.Nodes.Count).Parent.Text
    98.             Set NewNodeKey2 = tvPS.Nodes.Add((txtNewNodeKey1), tvwChild, txtNewNodeKey1 & "_" & OraFields2("PS_CPKEY") & "_MAT", OraFields2("PS_CPKEY"))
    99.             PSCPKEY = OraFields2("PS_CPKEY")
    100.             txtNewNodeKey = NewNodeKey2.Key
    101.             ProNodeCheck = OraFields2("PS_CPKEY").Value
    102.             ProNodeKey = NewNodeKey2.Key
    103.             Call Check_Node_Pro(ProNodeCheck, ProNodeKey)
    104.             Call Check_Node_Mat(PSCPKEY, txtNewNodeKey) 'Check for children nodes
    105.             OraDynaSet2.MoveNext
    106.             Loop
    107.         End If
    108. End Sub
    109. Private Sub Check_Node_Pro(ByVal ProNodeCheck As String, ByVal ProNodeKey As String)
    110.     Dim OraSession3 As OraSession
    111.     Dim OraDatabase3 As OraDatabase
    112.     Dim OraDynaSet3 As OraDynaSet
    113.     Dim OraFields3 As OraFields
    114.     Dim NewNodeKey3 As Node
    115.     Dim txtParentNode3 As String
    116.     Set OraSession3 = CreateObject("OracleInProcServer.XOraSession")
    117.     Set OraDatabase3 = OraSession3.OpenDatabase("QSDB", "QSDB_USER/5star5", 0&)
    118.     Set OraDynaSet3 = OraDatabase3.CreateDynaset("select RT_WCKEY,RT_OP_NUM from RT where RT_IMKEY = '" & ProNodeCheck & "'", 0&)
    119.     Set OraFields3 = OraDynaSet3.Fields
    120.         If OraFields3.Count = 0 Then 'Checks to see if the node has children nodes
    121.             Exit Sub 'If no children nodes, exit sub
    122.         Else
    123.             OraDynaSet3.MoveFirst 'If children nodes exist, create
    124.             Do While Not OraDynaSet3.EOF
    125.             txtParentNode3 = tvPS.Nodes(tvPS.Nodes.Count).Parent.Text
    126.             Set NewNodeKey3 = tvPS.Nodes.Add((ProNodeKey), tvwChild, ProNodeKey & "_" & OraFields3("RT_WCKEY") & OraFields3("RT_OP_NUM") & "_PRO", OraFields3("RT_WCKEY"))
    127.             OraDynaSet3.MoveNext
    128.             Loop
    129.         End If
    130. End Sub

    What I'd like to do is build the TreeView level by level so that I can sort the nodes before they are added to the TreeView, via Recordset.Sort. Can someone help me out? Thanks, Jeremy
    Last edited by JCScoobyRS; Apr 11th, 2003 at 02:13 PM.
    He who listens well, speaks well.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width