Link to home
Start Free TrialLog in
Avatar of Prysson
Prysson

asked on

help with treeview populate on demand

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);
               }
           }

        }


    }      
ASKER CERTIFIED SOLUTION
Avatar of AlexNek
AlexNek

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial