CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • Installing SQL Server 2008
  • Writing UDFs for Firebird Embedded SQL Server
  • [Updated] Shutdown Manager
  • Building Windows Azure Cloud Service Applications with Azure Storage and the Azure SDK

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > Visual Basic Programming > Visual Basic 6.0 Programming
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    Visual Basic 6.0 Programming Ask questions about VB 6.0 (or earlier versions) or help others by answering their question.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old July 31st, 2003, 07:01 AM
    azwildcat4ever azwildcat4ever is offline
    Member
     
    Join Date: Jul 2003
    Posts: 52
    azwildcat4ever is an unknown quantity at this point (<10)
    Expanding Tree View

    I have a tree view in my application. I already have a sub which collapses the entire tree. I need a sub which expand all the codes in the tree view. I am fairly new to vb.. Help greatly appreciate.. please ask any questions u have.

    here is the code to the Collapse sub

    Private Sub RepExpTV_Click()

    For k = 1 To TreeView1.Nodes.Count
    TreeView1.Nodes(k).Expanded = False

    Next k

    End Sub
    Reply With Quote
      #2    
    Old July 31st, 2003, 07:11 AM
    womalley womalley is offline
    Member
     
    Join Date: May 2003
    Location: upstate NY
    Posts: 168
    womalley is on a distinguished road (10+)
    Question:
    Are you collapsing nodes on the server side or on the client side?
    The reason that I ask is because there is a difference with how it would be handled.

    Will
    Reply With Quote
      #3    
    Old July 31st, 2003, 07:14 AM
    azwildcat4ever azwildcat4ever is offline
    Member
     
    Join Date: Jul 2003
    Posts: 52
    azwildcat4ever is an unknown quantity at this point (<10)
    The database file is on my computer. Its more like a TreeView (TV) I am playing about it. I have a Report Menu under which is the following choice. -> Collapse all entries in TreeView. I need to have a choice which Expands the entire treeview.

    Thank you
    Reply With Quote
      #4    
    Old July 31st, 2003, 07:15 AM
    azwildcat4ever azwildcat4ever is offline
    Member
     
    Join Date: Jul 2003
    Posts: 52
    azwildcat4ever is an unknown quantity at this point (<10)
    However when the application is used..ppl will go on the network to find the database file which is used to make the tree nodes
    Reply With Quote
      #5    
    Old July 31st, 2003, 07:31 AM
    womalley womalley is offline
    Member
     
    Join Date: May 2003
    Location: upstate NY
    Posts: 168
    womalley is on a distinguished road (10+)
    Edited:
    Sorry I did not understand the question.

    Last edited by womalley; July 31st, 2003 at 07:36 AM.
    Reply With Quote
      #6    
    Old July 31st, 2003, 07:43 AM
    womalley womalley is offline
    Member
     
    Join Date: May 2003
    Location: upstate NY
    Posts: 168
    womalley is on a distinguished road (10+)
    When the Menu option is clicked you need to fire a Server Side event that will load all the data for each node?

    Just to make sure... Do you have AutoPostBack set to true?
    Reply With Quote
      #7    
    Old July 31st, 2003, 08:44 AM
    Pinky98's Avatar
    Pinky98 Pinky98 is offline
    Senior Member
     
    Join Date: Dec 2002
    Location: London, UK
    Posts: 1,569
    Pinky98  is a jewel in the rough (300+)Pinky98  is a jewel in the rough (300+)Pinky98  is a jewel in the rough (300+)Pinky98  is a jewel in the rough (300+)
    maybe I am missing something, but don't you just do the same thing:

    Code:
    Private Sub cmdExpand_Click()
       For k = 1 To TreeView1.Nodes.Count
          TreeView1.Nodes(k).Expanded = True
       Next k
    End Sub
    __________________
    Mike
    Reply With Quote
      #8    
    Old July 31st, 2003, 10:23 AM
    womalley womalley is offline
    Member
     
    Join Date: May 2003
    Location: upstate NY
    Posts: 168
    womalley is on a distinguished road (10+)
    Quote:
    Originally posted by Pinky98
    maybe I am missing something, but don't you just do the same thing:

    Code:
    Private Sub cmdExpand_Click()
       For k = 1 To TreeView1.Nodes.Count
          TreeView1.Nodes(k).Expanded = True
       Next k
    End Sub
    I think what azwildcat4ever needs to do is a little more complex then that. Think of a Bill Of Material.
    Node
    |_______ Node
    |______ Node
    |________Node
    |________Node
    |________Node
    |______Node
    |______Node
    |_______ Node

    ect...
    He would like to expand ALL the nodes from what I understand so you have to drill down through all the child elements for each node.

    You will have to create a stored procedure that returns all children for each node then populate the tree from that. This will take a while to do tho, I would think about maybe scrapping this idea of expanding all the nodes. I like the idea of closing all nodes tho. very cool...

    Will
    Reply With Quote
      #9    
    Old July 31st, 2003, 10:32 AM
    azwildcat4ever azwildcat4ever is offline
    Member
     
    Join Date: Jul 2003
    Posts: 52
    azwildcat4ever is an unknown quantity at this point (<10)
    here is the code i think for expanding only a selected node. because expanding the entire tree takes alot of time and might not be need. My code for expanding at one point of the tree works. It works if i specify the node in the actual code.for example Set nodes(1) = Treeview1.nodes(3) but it doesnt work when want it to go from the selected item

    Private Sub RepExpTV_Click()
    Dim nodes(1 To 100) As Object
    Dim node As Object

    If TreeView1.SelectedItem Is Nothing Then
    Exit Sub
    End If
    Level = 1
    Set nodes(1) = TreeView1.nodes(1).Child
    While (Level > 0)
    If nodes(Level) Is Nothing Then
    Level = Level - 1
    If Level = 1 Then Exit Sub
    Set nodes(Level) = nodes(Level).Next
    Else
    Set node = nodes(Level)
    node.Expanded = True
    If node.Children > 0 Then
    Level = Level + 1
    Set nodes(Level) = node.Child
    Else
    Set nodes(Level) = nodes(Level).Next
    End If
    End If


    Wend
    Reply With Quote
      #10    
    Old July 31st, 2003, 10:47 AM
    womalley womalley is offline
    Member
     
    Join Date: May 2003
    Location: upstate NY
    Posts: 168
    womalley is on a distinguished road (10+)
    Quote:
    Originally posted by azwildcat4ever
    here is the code i think for expanding only a selected node. because expanding the entire tree takes alot of time and might not be need. My code for expanding at one point of the tree works. It works if i specify the node in the actual code.for example Set nodes(1) = Treeview1.nodes(3) but it doesnt work when want it to go from the selected item

    Private Sub RepExpTV_Click()
    Dim nodes(1 To 100) As Object
    Dim node As Object

    If TreeView1.SelectedItem Is Nothing Then
    Exit Sub
    End If
    Level = 1
    Set nodes(1) = TreeView1.nodes(1).Child
    While (Level > 0)
    If nodes(Level) Is Nothing Then
    Level = Level - 1
    If Level = 1 Then Exit Sub
    Set nodes(Level) = nodes(Level).Next
    Else
    Set node = nodes(Level)
    node.Expanded = True
    If node.Children > 0 Then
    Level = Level + 1
    Set nodes(Level) = node.Child
    Else
    Set nodes(Level) = nodes(Level).Next
    End If
    End If


    Wend
    I am guessing that you are using the SelectedIndexChange event to figure out what node was selected. I ran into a problem with this aswell. Try this. Make the first node in your tree empty so it is not seen by the user. Make sure that you set the selectednodeindex for the tree to 0. Now when you select a node in the tree the SelectedIndexChange event will fire and I think all will be well. Oh one quick question. is this menu done oncontext of the tree node or how is the menu being shown?

    on the tree view control put the following
    oncontextmenu="javascript: showMenu(this); return false;"

    now here is the function
    function showMenu(Item)
    {

    var NodeSelected = document.getElementById(Item.id).getTreeNode(event.treeNodeIndex);
    var NodeLevel = new Number(event.treeNodeIndex)
    var ParentNode = document.getElementById(Item.id).getTreeNode(event.treeNodeIndex).getParent();
    var NodeType = "";
    var TreeNodeIndex = 0;

    TreeNodeIndex = new String(NodeSelected.getNodeIndex());
    NodeType= new String(NodeSelected.getAttribute("type") );
    NodeType= NodeType.toUpperCase();

    }

    Last edited by womalley; July 31st, 2003 at 10:53 AM.
    Reply With Quote
      #11    
    Old July 31st, 2003, 10:48 AM
    Pinky98's Avatar
    Pinky98 Pinky98 is offline
    Senior Member
     
    Join Date: Dec 2002
    Location: London, UK
    Posts: 1,569
    Pinky98  is a jewel in the rough (300+)Pinky98  is a jewel in the rough (300+)Pinky98  is a jewel in the rough (300+)Pinky98  is a jewel in the rough (300+)
    Okay, so then just implement a tree search algorithm which, instead of finding an element, expands the tree!
    __________________
    Mike
    Reply With Quote
      #12    
    Old July 31st, 2003, 10:54 AM
    azwildcat4ever azwildcat4ever is offline
    Member
     
    Join Date: Jul 2003
    Posts: 52
    azwildcat4ever is an unknown quantity at this point (<10)
    where would i made the changes.. i am doing the change from a menu item// NOT Within by clicking the tree
    Reply With Quote
      #13    
    Old July 31st, 2003, 10:58 AM
    azwildcat4ever azwildcat4ever is offline
    Member
     
    Join Date: Jul 2003
    Posts: 52
    azwildcat4ever is an unknown quantity at this point (<10)
    Angry

    Is this the tree view control

    Private Sub TreeView1_DblClick()

    On Error GoTo fokop

    If TreeView1.SelectedItem.Image = "Arrow" Then
    TreeView1.StartLabelEdit
    End If
    fokop:

    End Sub
    Reply With Quote
      #14    
    Old July 31st, 2003, 11:16 AM
    womalley womalley is offline
    Member
     
    Join Date: May 2003
    Location: upstate NY
    Posts: 168
    womalley is on a distinguished road (10+)
    Quote:
    Originally posted by azwildcat4ever
    where would i made the changes.. i am doing the change from a menu item// NOT Within by clicking the tree
    So the event is onRightClick or OnContextMenu of the treeview node. In other words when you right click on a node you want to expand that node.

    on the tree view control put the following
    oncontextmenu="java script: showMenu(this); return false;"

    now when the user right clicks on the treeview your menu will show up that part you have done... When the user clicks a menu option you get the NodeIndex that was selected from the following function

    function showMenu(Item)
    {

    var NodeSelected = document.getElementById(Item.id).getTreeNode(event.treeNodeIndex);
    var NodeLevel = new Number(event.treeNodeIndex)
    var ParentNode = document.getElementById(Item.id).getTreeNode(event.treeNodeIndex).getParent();
    var NodeType = "";
    var TreeNodeIndex = 0;

    TreeNodeIndex = new String(NodeSelected.getNodeIndex());
    NodeType= new String(NodeSelected.getAttribute("type") );
    NodeType= NodeType.toUpperCase();

    }

    You could even make the variables global by putting then outside the function

    var NodeSelected = 0;
    var NodeLevel = 0;
    var ParentNode = 0;
    var NodeType = "";
    var TreeNodeIndex = 0;

    function showMenu(Item)
    {

    this.NodeSelected = document.getElementById(Item.id).getTreeNode(event.treeNodeIndex);
    this.NodeLevel = new Number(event.treeNodeIndex)
    this.ParentNode = document.getElementById(Item.id).getTreeNode(event.treeNodeIndex).getParent();
    this.NodeType = "";
    this.TreeNodeIndex = 0;

    this.TreeNodeIndex = new String(NodeSelected.getNodeIndex());
    this.NodeType= new String(NodeSelected.getAttribute("type") );
    this.NodeType= NodeType.toUpperCase();

    }

    Now when you click on your menu option you will know what the index of the node selected was. If you need to read this from a Server side function, then take the values that you need for that function and put them in a textbox or label. Make sure that visible is set to true or you will not be able to write to it from the client.
    Once you have the values in the textbox or label you can read them from the server side function/method or sub. I would use a textbox just because it is easier.

    will
    Reply With Quote
      #15    
    Old July 31st, 2003, 11:30 AM
    azwildcat4ever azwildcat4ever is offline
    Member
     
    Join Date: Jul 2003
    Posts: 52
    azwildcat4ever is an unknown quantity at this point (<10)
    when I right click on my node, I already have a pulldown menu which gives me the option to add items and delete and rename them too. How do I add this new function (of expanding that point on of the node). Thank very much
    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > Visual Basic Programming > Visual Basic 6.0 Programming


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 04:10 PM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
    Copyright WebMediaBrands Inc. 2002-2009