urgent please : treeview control expand collapse

  • Thread starter Thread starter Gönen EREN
  • Start date Start date
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.
 
....
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;
}
 
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=false;
MenuTree.GetNodeFromIndex(e.OldNode).Expanded=true;
}

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

------------------------------------------------------------
 
Back
Top