TreeNodeCollection & TreeNode not defined

Discussion in 'ASP .Net Web Controls' started by Patrick.O.Ige, Oct 20, 2004.

  1. I have this code below.
    All its suppose to do is to EXPAND / COLLAPSE ALL of my treeview.
    But when i use ASP.NET WEbmatrix it all works fine ..

    But with VS.NET is says TreeNodeCollection not defined
    and TreeNode not defined!!!!!!!!!!!!!!arg!!!!

    How am i suppose to define it in VS.NET..
    OR Does anybody another way of doing it!!
    Any help appreciated!


    Private Sub expandAll(ByVal sender As Object, ByVal e As EventArgs)
    'Call the recursive function with the rootnode collection and a
    boolean value indication to expand the nodes.
    expandCollapseAllTreeviewNodes(Me.tvFamilyTree.Nodes, True)
    End Sub

    Private Sub collapseAll(ByVal sender As Object, ByVal e As EventArgs)
    'Call the recursive function with the rootnode collection and a
    boolean value indication to collapse the nodes.
    expandCollapseAllTreeviewNodes(Me.tvFamilyTree.Nodes, False)
    End Sub

    'Recursive function.
    Private Sub expandCollapseAllTreeviewNodes(ByVal nodes As
    TreeNodeCollection, ByVal expand As Boolean)
    Dim node As TreeNode

    'Loop through each node of the collection and expand it.
    For Each node In nodes
    node.Expanded = expand

    'Call the recursive function from itself, just the subnode
    collection (this will ensure all nodes either are collapsed or expanded).
    expandCollapseAllTreeviewNodes(node.Nodes, expand)

    Next
    End Sub

    ASP.NET
    -----------
    <asp:Button id="Button1" onclick="expandAll" runat=server
    Text="Expand"></asp:Button>
    <asp:Button id="Button2" onclick="collapseAll"
    Text="Collapse"></asp:Button>
     
    Patrick.O.Ige, Oct 20, 2004
    #1
    1. Advertising

  2. Hello Patrick,
    I tried the scenario as follows and it worked.
    I added a tree view class to my web page in vs.net 2003 and created nodes
    in it.
    I added 2 buttons and inserted the code you sent in your e-mail (changed
    Me.tvFamilyTree.Nodes to Me.TreeView1.Nodes)


    I ran the project and pressed the collapse and exapnd buttons. Things
    worked as expected and exapnsion and collapsing worked fine.


    Is there a special case that you are having in your treeview?
    Are the nodes created dynamically? I created my nodes statically here?

    Regards
    Mohamed El Ashmawy
    MEA Developer Support Center
    ITWorx on behalf of Microsoft EMEA GTSC
     
    Mohamed El Ashmawy, Oct 20, 2004
    #2
    1. Advertising

  3. thx Mohammed.
    My treeView is populsted using XML
    And my code works well in ASP.NET WEMATRIX
    Only when i use Visual Studio it says :- TreeNodeCollection and TreeNode
    are not defined.
    How should i define that..
    Can you just post your full code i guess it will help me!
    Thanks!!



    ""Mohamed El Ashmawy"" wrote:

    > Hello Patrick,
    > I tried the scenario as follows and it worked.
    > I added a tree view class to my web page in vs.net 2003 and created nodes
    > in it.
    > I added 2 buttons and inserted the code you sent in your e-mail (changed
    > Me.tvFamilyTree.Nodes to Me.TreeView1.Nodes)
    >
    >
    > I ran the project and pressed the collapse and exapnd buttons. Things
    > worked as expected and exapnsion and collapsing worked fine.
    >
    >
    > Is there a special case that you are having in your treeview?
    > Are the nodes created dynamically? I created my nodes statically here?
    >
    > Regards
    > Mohamed El Ashmawy
    > MEA Developer Support Center
    > ITWorx on behalf of Microsoft EMEA GTSC
    >
    >
     
    Patrick.O.Ige, Oct 21, 2004
    #3
  4. thx Mohammed.
    My treeView is populsted using XML
    And my code works well in ASP.NET WEMATRIX
    Only when i use Visual Studio it says :- TreeNodeCollection and TreeNode
    are not defined.
    How should i define that..
    Can you just post your full code i guess it will help me!
    Thanks!!


    ""Mohamed El Ashmawy"" wrote:

    > Hello Patrick,
    > I tried the scenario as follows and it worked.
    > I added a tree view class to my web page in vs.net 2003 and created nodes
    > in it.
    > I added 2 buttons and inserted the code you sent in your e-mail (changed
    > Me.tvFamilyTree.Nodes to Me.TreeView1.Nodes)
    >
    >
    > I ran the project and pressed the collapse and exapnd buttons. Things
    > worked as expected and exapnsion and collapsing worked fine.
    >
    >
    > Is there a special case that you are having in your treeview?
    > Are the nodes created dynamically? I created my nodes statically here?
    >
    > Regards
    > Mohamed El Ashmawy
    > MEA Developer Support Center
    > ITWorx on behalf of Microsoft EMEA GTSC
    >
    >
     
    Patrick.O.Ige, Oct 21, 2004
    #4
  5. SelectedNodeIndex cannot be set to an undisplayed node(TreeView Er

    Thx Mohammed....
    The Expand Collapse is working good now.
    But i don't know whether u noticed someting funny about it.
    When u EXPAND the Nodes and then select a node and then Press Collapse it
    gives Error:-

    "SelectedNodeIndex cannot be set to an undisplayed node (all parents of a
    selected node must be expanded)"

    Let me kow how you go!!!


    ""Mohamed El Ashmawy"" wrote:

    > Hello Patrick,
    > I tried the scenario as follows and it worked.
    > I added a tree view class to my web page in vs.net 2003 and created nodes
    > in it.
    > I added 2 buttons and inserted the code you sent in your e-mail (changed
    > Me.tvFamilyTree.Nodes to Me.TreeView1.Nodes)
    >
    >
    > I ran the project and pressed the collapse and exapnd buttons. Things
    > worked as expected and exapnsion and collapsing worked fine.
    >
    >
    > Is there a special case that you are having in your treeview?
    > Are the nodes created dynamically? I created my nodes statically here?
    >
    > Regards
    > Mohamed El Ashmawy
    > MEA Developer Support Center
    > ITWorx on behalf of Microsoft EMEA GTSC
    >
    >
     
    Patrick.O.Ige, Oct 22, 2004
    #5
  6. RE: SelectedNodeIndex cannot be set to an undisplayed node(TreeView Er

    Hello Patrick,
    I am sorry for the delay in my reply.
    I am happy that the exapnd/collapse problem is over.
    As for the error you get. It means that you are trying to set the selection
    for a node that is under collapsed node (i.e. the node you are selecting is
    actually not apparent on the screen).
    Do you have code in your pageload event that selects a specific node? If
    so, then you need to check that all the node hierarchy (from that node to
    the root) as expanded. If not, then don't select the node.

    The problem you described is not apparent on my side because I don't have
    any code that selects a node.
    The code I am using is taken from the code you posted and here it is:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles Button1.Click
    expandCollapseAllTreeviewNodes(Me.TreeView1.Nodes, True)

    End Sub


    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles Button2.Click
    expandCollapseAllTreeviewNodes(Me.TreeView1.Nodes, False)
    End Sub

    Private Sub expandCollapseAllTreeviewNodes(ByVal nodes As
    TreeNodeCollection, ByVal expand As Boolean)
    Dim node As TreeNode

    'Loop through each node of the collection and expand it.
    For Each node In nodes
    node.Expanded = expand

    'Call the recursive function from itself, just the subnode
    collection (this will ensure all nodes either are collapsed or expanded).
    expandCollapseAllTreeviewNodes(node.Nodes, expand)

    Next
    End Sub


    As for the treeview contents, they are all statically added using the
    VS.Net IDE

    Regards
    Mohamed El Ashmawy
    MEA Developer Support Center
    ITWorx on behalf of Microsoft EMEA GTSC
     
    Mohamed El Ashmawy, Nov 19, 2004
    #6
  7. RE: SelectedNodeIndex cannot be set to an undisplayed node(TreeVie

    Thx for the reply mohammed!
    I will check my code again and get back to you...
    What my question is again is that when i collapse why does it collapse
    totally..
    I want it to collpapse to top nodes only and cot collapse to the root node.
    Thx
    Patrick

    ""Mohamed El Ashmawy"" wrote:

    > Hello Patrick,
    > I am sorry for the delay in my reply.
    > I am happy that the exapnd/collapse problem is over.
    > As for the error you get. It means that you are trying to set the selection
    > for a node that is under collapsed node (i.e. the node you are selecting is
    > actually not apparent on the screen).
    > Do you have code in your pageload event that selects a specific node? If
    > so, then you need to check that all the node hierarchy (from that node to
    > the root) as expanded. If not, then don't select the node.
    >
    > The problem you described is not apparent on my side because I don't have
    > any code that selects a node.
    > The code I am using is taken from the code you posted and here it is:
    > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
    > System.EventArgs) Handles Button1.Click
    > expandCollapseAllTreeviewNodes(Me.TreeView1.Nodes, True)
    >
    > End Sub
    >
    >
    > Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
    > System.EventArgs) Handles Button2.Click
    > expandCollapseAllTreeviewNodes(Me.TreeView1.Nodes, False)
    > End Sub
    >
    > Private Sub expandCollapseAllTreeviewNodes(ByVal nodes As
    > TreeNodeCollection, ByVal expand As Boolean)
    > Dim node As TreeNode
    >
    > 'Loop through each node of the collection and expand it.
    > For Each node In nodes
    > node.Expanded = expand
    >
    > 'Call the recursive function from itself, just the subnode
    > collection (this will ensure all nodes either are collapsed or expanded).
    > expandCollapseAllTreeviewNodes(node.Nodes, expand)
    >
    > Next
    > End Sub
    >
    >
    > As for the treeview contents, they are all statically added using the
    > VS.Net IDE
    >
    > Regards
    > Mohamed El Ashmawy
    > MEA Developer Support Center
    > ITWorx on behalf of Microsoft EMEA GTSC
    >
    >
     
    Patrick.O.Ige, Nov 20, 2004
    #7
  8. Patrick.O.Ige

    naija naija Guest

    RE: SelectedNodeIndex cannot be set to an undisplayed node(TreeView Er

    Hi Mohamed El Ashmawy,
    Thx for the response!
    I have looked through the code again but i still get the same error(I
    get the error only when i select a node and i click to collapse!And
    again when i select ROOT it collapse with no error but IT COLLAPSE
    TOTALLY TO THE ROOT LEVEL):-

    "The node at index 0.1 is not currently displayed in the tree.
    SelectedNodeIndex cannot be set to an undisplayed node (all parents of a
    selected node must be expanded)."

    And i don't have any code in the Page_Load.
    the code 'm using looks like this:-

    Private Sub expandCollapseAllTreeviewNodes(ByVal nodes As
    TreeNodeCollection, ByVal expand As Boolean)
    Dim node As TreeNode

    'Loop through each node of the collection and expand it.
    For Each node In nodes
    node.Expanded = expand

    'Call the recursive function from itself, just the subnode
    collection (this will ensure all nodes either are collapsed or
    expanded).
    expandCollapseAllTreeviewNodes(node.Nodes, expand)

    Next
    End Sub


    Sub Button2_Click(ByVal sender As Object, ByVal e As
    System.EventArgs)
    Me.expandCollapseAllTreeviewNodes(tvFamilyTree.Nodes, False)
    End Sub 'Button2_Click

    Sub Button1_Click(ByVal sender As Object, ByVal e As
    System.EventArgs)
    Me.expandCollapseAllTreeviewNodes(tvFamilyTree.Nodes, True)
    End Sub 'Button2_Click

    Thx Mohammed and let me read from you.



    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    naija naija, Nov 22, 2004
    #8
  9. RE: SelectedNodeIndex cannot be set to an undisplayed node(TreeView Er

    Hello Patrick,
    The function that you have "expandCollapseAllTreeviewNodes" expands or
    collapses all the nodes. This function iterates through all the nodes and
    collapses them all. i.e. This is the behavior expected of your code.
    If you want to collapse the selected node only you should write code like
    this one:
    Dim node As TreeNode =
    Me.TreeView1.GetNodeFromIndex(Me.TreeView1.SelectedNodeIndex)
    node.Expanded = False

    Since your code collapses all node to the root. If you have a node
    selected, then this would give the error you get.
    Thus, you should specify the needed behavior and re-implement the collapse
    method according to your requirements.

    Regards
    Mohamed El Ashmawy
    MEA Developer Support Center
    ITWorx on behalf of Microsoft EMEA GTSC
     
    Mohamed El Ashmawy, Nov 23, 2004
    #9
  10. Patrick.O.Ige

    naija naija Guest

    RE: SelectedNodeIndex cannot be set to an undisplayed node(TreeView Er

    Mohamed El Ashmawy,
    Thx for the reply.
    What i just want is just for the Node to expand all the nodes and
    Collapse(Not to the root but to the Sub Nodes)
    Can you pls POST me the full code or forward me the resources to do
    this!
    Thx alot!




    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    naija naija, Nov 24, 2004
    #10
  11. RE: SelectedNodeIndex cannot be set to an undisplayed node(TreeView Er

    Dear Patrick,
    I am not sure I understand your requirement totally, but this code:
    Dim node As TreeNode =
    Me.TreeView1.GetNodeFromIndex(Me.TreeView1.SelectedNodeIndex)
    node.Expanded = False

    would collapse the selected node. i.e. if you select a node and put this
    code in the event handler for a button, then the selected node will be
    collapsed (all its children will not bi displayed).
    Is that what you need?

    Regards
    Mohamed El Ashmawy
    MEA Developer Support Center
    ITWorx on behalf of Microsoft EMEA GTSC
     
    Mohamed El Ashmawy, Nov 25, 2004
    #11
  12. RE: SelectedNodeIndex cannot be set to an undisplayed node(TreeVie

    Yes thats what i want but where is the code supposed to be placed?
    I explained to you that i just want it to EXPAND totally and collapse to
    nodes(Not totally to the ROOT).With my code below just specify how i should
    do it!
    Thx (My code below)

    My code is as follows:-
    Private Sub expandCollapseAllTreeviewNodes(ByVal nodes As
    TreeNodeCollection, ByVal expand As Boolean)
    Dim node As TreeNode
    'Loop through each node of the collection and expand it.
    For Each node In nodes
    If expand Then
    node.Expanded = True
    expandCollapseAllTreeviewNodes(node.Nodes, expand)
    Else
    node.Expanded = False
    expandCollapseAllTreeviewNodes(node.Nodes, expand)
    End If

    Next
    End Sub

    Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    Me.expandCollapseAllTreeviewNodes(tvFamilyTree.Nodes, False)
    End Sub 'Button2_Click

    Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    Me.expandCollapseAllTreeviewNodes(tvFamilyTree.Nodes, True)
    End Sub 'Button2_Click











    ""Mohamed El Ashmawy"" wrote:

    > Dear Patrick,
    > I am not sure I understand your requirement totally, but this code:
    > Dim node As TreeNode =
    > Me.TreeView1.GetNodeFromIndex(Me.TreeView1.SelectedNodeIndex)
    > node.Expanded = False
    >
    > would collapse the selected node. i.e. if you select a node and put this
    > code in the event handler for a button, then the selected node will be
    > collapsed (all its children will not bi displayed).
    > Is that what you need?
    >
    > Regards
    > Mohamed El Ashmawy
    > MEA Developer Support Center
    > ITWorx on behalf of Microsoft EMEA GTSC
    >
    >
     
    Patrick.O.Ige, Nov 29, 2004
    #12
  13. RE: SelectedNodeIndex cannot be set to an undisplayed node(TreeVie

    Hello Patrick,
    If you want to collapse the selected node when button2 is clicked, then you
    should put inside its click event:
    Dim node As TreeNode =
    Me.TreeView1.GetNodeFromIndex(Me.TreeView1.SelectedNodeIndex)
    node.Expanded = False

    instead of :
    Me.expandCollapseAllTreeviewNodes(tvFamilyTree.Nodes, False)


    i.e. your code would be as follows:


    Private Sub expandCollapseAllTreeviewNodes(ByVal nodes As
    TreeNodeCollection, ByVal expand As Boolean)
    Dim node As TreeNode
    'Loop through each node of the collection and expand it.
    For Each node In nodes
    If expand Then
    node.Expanded = True
    expandCollapseAllTreeviewNodes(node.Nodes, expand)
    Else
    node.Expanded = False
    expandCollapseAllTreeviewNodes(node.Nodes, expand)
    End If

    Next
    End Sub

    'This is what I changed
    Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    Dim node As TreeNode =
    Me.TreeView1.GetNodeFromIndex(Me.TreeView1.SelectedNodeIndex)
    node.Expanded = False
    End Sub 'Button2_Click

    Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    Me.expandCollapseAllTreeviewNodes(tvFamilyTree.Nodes, True)
    End Sub 'Button2_Click


    Regards
    Mohamed El Ashmawy
    MEA Developer Support Center
    ITWorx on behalf of Microsoft EMEA GTSC
     
    Mohamed El Ashmawy, Nov 29, 2004
    #13
  14. RE: SelectedNodeIndex cannot be set to an undisplayed node(TreeVie

    Hi Mohammed!
    Thx for the explanation!.
    Patrick
    ** If i have more Questions i'll be here**

    ""Mohamed El Ashmawy"" wrote:

    > Hello Patrick,
    > If you want to collapse the selected node when button2 is clicked, then you
    > should put inside its click event:
    > Dim node As TreeNode =
    > Me.TreeView1.GetNodeFromIndex(Me.TreeView1.SelectedNodeIndex)
    > node.Expanded = False
    >
    > instead of :
    > Me.expandCollapseAllTreeviewNodes(tvFamilyTree.Nodes, False)
    >
    >
    > i.e. your code would be as follows:
    >
    >
    > Private Sub expandCollapseAllTreeviewNodes(ByVal nodes As
    > TreeNodeCollection, ByVal expand As Boolean)
    > Dim node As TreeNode
    > 'Loop through each node of the collection and expand it.
    > For Each node In nodes
    > If expand Then
    > node.Expanded = True
    > expandCollapseAllTreeviewNodes(node.Nodes, expand)
    > Else
    > node.Expanded = False
    > expandCollapseAllTreeviewNodes(node.Nodes, expand)
    > End If
    >
    > Next
    > End Sub
    >
    > 'This is what I changed
    > Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    > Dim node As TreeNode =
    > Me.TreeView1.GetNodeFromIndex(Me.TreeView1.SelectedNodeIndex)
    > node.Expanded = False
    > End Sub 'Button2_Click
    >
    > Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    > Me.expandCollapseAllTreeviewNodes(tvFamilyTree.Nodes, True)
    > End Sub 'Button2_Click
    >
    >
    > Regards
    > Mohamed El Ashmawy
    > MEA Developer Support Center
    > ITWorx on behalf of Microsoft EMEA GTSC
    >
    >
     
    Patrick.O.Ige, Nov 30, 2004
    #14
  15. RE: SelectedNodeIndex cannot be set to an undisplayed node(TreeVie

    Anytime, :)
    If you have any further questions or problems, plesae do not hesitate to
    post them

    Regards
    Mohamed El Ashmawy
    MEA Developer Support Center
    ITWorx on behalf of Microsoft EMEA GTSC
     
    Mohamed El Ashmawy, Nov 30, 2004
    #15
  16. Patrick.O.Ige

    Guest

    Re: SelectedNodeIndex cannot be set to an undisplayed node(TreeView Er

    Not sure if this is what you're looking for but perhaps this can help
    with the
    "SelectedNodeIndex cannot be set to an undisplayed..." error


    private void ExpandFromRoot(string nodeID){
    string[] nodeIDs = nodeID.Split(new char[] {'.'});
    string tmpId = "";
    foreach(string id in nodeIDs){
    tmpId += id;
    treeView.GetNodeFromIndex(tmpId).Expanded = true;
    tmpId += ".";
    }
    }

    Regards,
    S Beskur
     
    , Dec 8, 2004
    #16
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. naijacoder naijacoder
    Replies:
    1
    Views:
    669
    naijacoder naijacoder
    Sep 15, 2004
  2. Patrick Olurotimi Ige
    Replies:
    2
    Views:
    537
    Patrick Olurotimi Ige
    Feb 15, 2005
  3. tanya foster
    Replies:
    3
    Views:
    3,732
    tanya foster
    May 18, 2006
  4. Oodini
    Replies:
    1
    Views:
    1,777
    Keith Thompson
    Sep 27, 2005
  5. Replies:
    1
    Views:
    504
    Sion Arrowsmith
    Jul 10, 2008
Loading...

Share This Page