Solved

help with treeview populate on demand

Posted on 2007-03-17
1
2,895 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
1 Comment
 
LVL 16

Accepted Solution

by:
AlexNek earned 500 total points
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

763 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now