Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

help with treeview populate on demand

Posted on 2007-03-17
1
Medium Priority
?
2,981 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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

670 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