By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,306 Members | 1,621 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,306 IT Pros & Developers. It's quick & easy.

urgent please : treeview control expand collapse

P: n/a
how can i collapse or expand a node of treeview control programmaticly?
thanks.
Nov 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
"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

P: n/a
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.