Solved

help with treeview populate on demand

Posted on 2007-03-17
1
2,962 Views
Last Modified: 2010-05-18
I have an issue where I am tryiong to populate a treeview programmaticaly and I would like to populate all of the child nodes "ondemand" using the populateondemand

however if I set a node to populateondemand = true;

I get the error

"PopulateOnDemand can't be set to true on a node that already has children."  

It seems pretty obvious to me that  dont understand the correct way to impliment this.

Could someone take a look at my code and suggest o me a way to have the child objects starting from the root level only populate when someones expands the node?

this is my code that fills the Treeview.

protected void Page_Load(object sender, EventArgs e)
    {
   

                     tvAreaTableAdapter tvAreaAdapt = new tvAreaTableAdapter();


        TreeviewDS.tvAreaDataTable areaDT = tvAreaAdapt.GetArea();
   
     
       
       
       
       foreach (DataRow r1 in areaDT)
       {
         
           long areaID = Convert.ToInt64(r1["AreaID"]);
           TreeNode anode = new TreeNode();        
           anode.Text = "Area " + r1["AreaName"].ToString();
           anode.Value = r1["AreaID"].ToString();

           anode.PopulateOnDemand = true;
     
           TreeView1.Nodes.Add(anode);
           
         
           tvRowTableAdapter tvRowAdapt = new tvRowTableAdapter();
           TreeviewDS.tvRowDataTable rowDT = tvRowAdapt.GetRows(areaID);

           foreach (DataRow r2 in rowDT)
           {
               long rowID = Convert.ToInt64(r2["RowID"]);
               TreeNode rnode = new TreeNode();
               rnode.Text = "Row " + r2["RowNumber"].ToString();
               rnode.Value = r2["RowID"].ToString();
              rnode.PopulateOnDemand = true;
             
               anode.ChildNodes.Add(rnode);

               tvVineTableAdapter tvVineAdapt = new tvVineTableAdapter();
               TreeviewDS.tvVineDataTable vineDT = tvVineAdapt.GetVines(rowID);

               foreach (DataRow r3 in vineDT)
               {
                   TreeNode vnode = new TreeNode();
                   vnode.Text = "Vine " + r3["Vine"].ToString();
                   vnode.Value = r3["VineID"].ToString();
                   rnode.ChildNodes.Add(vnode);
               }
           }

        }


    }      
0
Comment
Question by:Prysson
[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
1 Comment
 
LVL 16

Accepted Solution

by:
AlexNek earned 500 total points
ID: 18743133
You musn't fill the full tree at the begin and you need an event handler for PopulateNode
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.treenode.populateondemand.aspx
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

634 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