Solved

problem with TreeNodeExpanded event System.Web.UI.WeBControls)

Posted on 2010-08-25
4
679 Views
Last Modified: 2013-11-08
Hi!
I 've inserted a TreeView Control into my WebPart class. Everything works properly as long as i don't try tu use TreeNodeExpanded event.When i do that after expanding root the whole control collaps and returns to original state - where all leafs are hidden. Some sample code below.I 've created this control as a class library because later on ideploy my web part to sharepoint services. In general what i want to get is formating text of each node after expanding the tree so that all elements where in proper "column".
in advance thank you for your help
_treeView.TreeNodeExpanded += new TreeNodeEventHandler(someAction);


public void someAction(object sender, EventArgs args)
        {
            this.l1.Text = "dasda";
        }

Open in new window

0
Comment
Question by:Mateusz_Smietanka
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 5

Expert Comment

by:Akin Delu
ID: 33522897
does your treeView get populated from database, if so check your page_load event confirm that you have
if (!Page.IsPostBack)
{
             //your database binding code goes here
}
0
 
LVL 16

Expert Comment

by:Vikram Singh Saini
ID: 33528743
0
 

Accepted Solution

by:
Mateusz_Smietanka earned 0 total points
ID: 33528971
I programmatically populate the tree basing on querry send to SSAS.
private void CreateTreeStruct()
        {
            AdomdConnection conn = new AdomdConnection("Data Source=v-poldim;Catalog=testCube");
            conn.Open();
            AdomdCommand command = new AdomdCommand("select {[Measures].[amount],[measures].[assumption]} on 0,{[proj].[hierarchy].MEMBERS} on 1 from [AX5 SP1 POLDIM SANDBOX] ", conn);
            CellSet _cellSet = command.ExecuteCellSet();
            // get an axe, ax.1 == rows
            Axis axe = _cellSet.Axes[1];
            cc = _cellSet.Cells;
            int k = 0;
            MyTreeNode parent = null;

            foreach (Position position in axe.Positions)
            {
                //Console.WriteLine(position.Members[0].Caption);
                this.AddChild(ref parent, position.Members[0].Caption, GetLabelText(position.Members[0].Caption));
                k += 2;

            }
           // _treeView = new TreeView();
            _treeView.ControlStyle.Font.Name = "Courier New";
            //_treeView.ControlStyle.BackColor = Color.Beige;
            _treeView.ControlStyle.Font.Size = 12;
            panel = new Panel();
            l1 = new Label();
            l1.Text =" Project    Ammount    Assumption";
            l1.BackColor = Color.FromArgb(255,100,100,100);
            l1.Font.Size = 13;
            l1.Width = _treeView.Width;
            panel.Controls.Add(l1);
            panel.Controls.Add(_treeView);
            _treeView.Nodes.Add(parent);
           
           
            
            this.Controls.Add(panel);
            
        }
private void AddChild(ref MyTreeNode parent, String childValue, string label)
        {

            if (parent == null)
            {
                parent = new MyTreeNode(label, childValue);
                
                /* label= "       " + label;
                 label = label.Replace(" "," ");
                 parent.Text = label;*/

                return;
            }
            if (parent.ChildNodes.Count == 0)
            {
                parent.ChildNodes.Add(new MyTreeNode(label, childValue));
                return;
            }
            if (childValue.Length == 0)
                return;

            MyTreeNode node = null;
            //foreach (MyTreeNode node in parent.ChildNodes)
            for (int i = 0; i < parent.ChildNodes.Count; i++)
            {
                node = (MyTreeNode)parent.ChildNodes[i];
                switch (isAncestor(node.Value, childValue))
                {
                    case -1:
                        //parent.ChildNodes.Add(new MyTreeNode(childName, null));
                        //return;
                        break;
                    case 0:
                        this.AddChild(ref node, childValue, label);
                        return;
                    case 1:
                        node.ChildNodes.Add(new MyTreeNode(label, childValue));
                        return; ;
                }
            }

            parent.ChildNodes.Add(new MyTreeNode(label, childValue));


        }

Open in new window

0

Featured Post

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ASP.NET Calendar Control 5 52
PowerShell: ForEach-Object Export to CSV 4 91
Check only one toolstripmenu item 12 60
asp.net mvc5 6 33
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question