urgent please : treeview control expand collapse

Discussion in 'ASP .Net' started by Gönen EREN, Aug 16, 2003.

  1. Gönen EREN

    Gönen EREN Guest

    how can i collapse or expand a node of treeview control programmaticly?
    thanks.
     
    Gönen EREN, Aug 16, 2003
    #1
    1. Advertising

  2. Gönen EREN

    Alvin Bruney Guest

    each node contains a collapse property have a look at your object browser
    "Gönen EREN" <> wrote in message
    news:OR$6pn$...
    > how can i collapse or expand a node of treeview control programmaticly?
    > thanks.
    >
    >
     
    Alvin Bruney, Aug 16, 2003
    #2
    1. Advertising

  3. Gönen EREN

    Gönen EREN Guest

    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:...
    > each node contains a collapse property have a look at your object browser
    > "Gönen EREN" <> wrote in message
    > news:OR$6pn$...
    > > how can i collapse or expand a node of treeview control programmaticly?
    > > thanks.
    > >
    > >

    >
    >
     
    Gönen EREN, Aug 16, 2003
    #3
  4. "Gönen EREN" <> wrote in message
    news:...
    ....
    > 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
     
    John Saunders, Aug 16, 2003
    #4
  5. Gönen EREN

    Gönen EREN Guest

    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
    [...]
    }
    }

    ------------------------------------------------------------
     
    Gönen EREN, Aug 16, 2003
    #5
    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. Edwin Knoppert
    Replies:
    1
    Views:
    5,176
    Edwin Knoppert
    Nov 9, 2005
  2. vivek
    Replies:
    2
    Views:
    6,233
    pushp
    Jun 14, 2007
  3. jim
    Replies:
    0
    Views:
    564
  4. Reeya

    Treeview Control Expand Collapse

    Reeya, Jan 31, 2005, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    289
    Reeya
    Jan 31, 2005
  5. M.L.
    Replies:
    9
    Views:
    301
Loading...

Share This Page