468,556 Members | 2,387 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,556 developers. It's quick & easy.

urgent please : treeview control expand collapse

how can i collapse or expand a node of treeview control programmaticly?
thanks.
Nov 17 '05 #1
4 3197
each node contains a collapse property have a look at your object browser
"Gönen EREN" <ge***@gsu.edu.tr> wrote in message
news:OR**************@TK2MSFTNGP10.phx.gbl...
how can i collapse or expand a node of treeview control programmaticly?
thanks.

Nov 17 '05 #2
There is an event handler collapse but i couldn't find a collapse or expand
method
for example for a treeview object like :

<iewc:TreeView id="MenuTree" runat="server"
onselectedindexchanged="MenuTreeSelectChanged">
<iewc:TreeNode Text="A"></iewc:TreeNode>
<iewc:TreeNode Text="B">
<iewc:TreeNode Text="B1"></iewc:TreeNode>
<iewc:TreeNode Text="B2"></iewc:TreeNode>
<iewc:TreeNode Text="B3"></iewc:TreeNode>
<iewc:TreeNode Text="B4"></iewc:TreeNode>
</iewc:TreeNode>
<iewc:TreeNode Text="C">
<iewc:TreeNode Text="C1"></iewc:TreeNode>
<iewc:TreeNode Text="C2"></iewc:TreeNode>
<iewc:TreeNode Text="C3"></iewc:TreeNode>
</iewc:TreeNode>
</iewc:TreeView>

what should i use in

public void MenuTreeSelectChanged(Object sender, TreeViewSelectEventArgs e)
{

}

i want only the the "e.NewNode" to be expanded and collapse the "e.OldNode"

thanks for your help.
"Alvin Bruney" <vapordan_spam_me_not@hotmail_no_spamhotmail.com > wrote in
message news:OF*************@tk2msftngp13.phx.gbl...
each node contains a collapse property have a look at your object browser
"Gönen EREN" <ge***@gsu.edu.tr> wrote in message
news:OR**************@TK2MSFTNGP10.phx.gbl...
how can i collapse or expand a node of treeview control programmaticly?
thanks.


Nov 17 '05 #3
"Gönen EREN" <ge***@gsu.edu.tr> wrote in message
news:e3**************@TK2MSFTNGP09.phx.gbl...
....
what should i use in

public void MenuTreeSelectChanged(Object sender, TreeViewSelectEventArgs e) {

}

i want only the the "e.NewNode" to be expanded and collapse the "e.OldNode"
thanks for your help.


Give this a try. I haven't tested it, but it compiles:

public void MenuTreeSelectChanged(Object sender, TreeViewSelectEventArgs e)
{
TreeView treeView = (TreeView) sender;

TreeNode oldNode = treeView.GetNodeFromIndex(e.OldNode);
oldNode.Expanded = false;

TreeNode newNode = treeView.GetNodeFromIndex(e.NewNode);
newNode.Expanded = true;
}

--
John Saunders
Internet Engineer
jo***********@surfcontrol.com
Nov 17 '05 #4
it compiles but it doesn't work =(
i have also tried this one but the same thing no effect...
do you have any other ideas?

i use code behind, my code looks like:
------------------------------------------------------------
[...]

<iewc:TreeView id="MenuTree" runat="server"
onselectedindexchanged="MenuTreeSelectChanged">
<iewc:TreeNode Text="A"></iewc:TreeNode>
<iewc:TreeNode Text="B">
<iewc:TreeNode Text="B1"></iewc:TreeNode>
<iewc:TreeNode Text="B2"></iewc:TreeNode>
<iewc:TreeNode Text="B3"></iewc:TreeNode>
<iewc:TreeNode Text="B4"></iewc:TreeNode>
</iewc:TreeNode>
<iewc:TreeNode Text="C">
<iewc:TreeNode Text="C1"></iewc:TreeNode>
<iewc:TreeNode Text="C2"></iewc:TreeNode>
<iewc:TreeNode Text="C3"></iewc:TreeNode>
</iewc:TreeNode>
</iewc:TreeView>

[...]
------------------------------------------------------------

namespace ControlCenter
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Microsoft.Web.UI.WebControls;

public abstract class Menu : System.Web.UI.UserControl
{
protected Microsoft.Web.UI.WebControls.TreeView MenuTree;

private void Page_Load(object sender, System.EventArgs e){}

public void MenuTreeSelectChanged(Object sender,
TreeViewSelectEventArgs e)
{
// This doesn't work...
MenuTree.GetNodeFromIndex(e.OldNode).Expanded=fals e;
MenuTree.GetNodeFromIndex(e.OldNode).Expanded=true ;
}

//region Web Form Designer generated code
[...]
}
}

------------------------------------------------------------
Nov 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Stephen | last post: by
1 post views Thread by christoffer.lantz | last post: by
3 posts views Thread by Shawn | last post: by
reply views Thread by Tor Inge Rislaa | last post: by
reply views Thread by Tor Inge Rislaa | last post: by
reply views Thread by Tor Inge Rislaa | last post: by
6 posts views Thread by Andrew Poulos | last post: by
1 post views Thread by UniDue | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.