Click here to Skip to main content
15,077,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using TreeView in my project to hierarchical display of my data from database. It works fine for small amount of data say 500 nos. But when it exceeds that nos. it is taking too much time for loading. I have to populate large amount of data (say 2500 nos.). I have one table named as "tRegistered" from where i bind "Date" column as treeview Parent Node. And again from the same table i bind "Users" column as treeview Node. My objective is to display all registered users for the last 7 days in a hierarchical way. Somebody please help me.

My code is:

private void PopulateTreeView()


        SqlDataAdapter daPatient = new SqlDataAdapter("SELECT TOP 100 PERCENT pId, pDate, pName FROM tRegistered WHERE pDate >= DATEADD(day,-7, GETDATE())", con);
        SqlDataAdapter daDate = new SqlDataAdapter("SELECT     TOP 100 PERCENT pDate FROM  tRegistered
             WHERE     pDate >= DATEADD(day, - 7, GETDATE()))
             GROUP BY pDate
             ORDER BY pDate DESC", con);

        DataSet ds = new DataSet();
        daPatient.Fill(ds, "tRegistered");
        daDate.Fill(ds, "tRegistered");

            //Add root node
            TreeNode root = new TreeNode("Registered");
            treeView1.Nodes.Add(root);      //Hard code

            ds.Relations.Add("Regsd", ds.Tables["tRegistered"].Columns["pDate"], ds.Tables["tRegistered"].Columns["pDate"]);
            foreach (DataRow dr in ds.Tables["tRegistered"].Rows)

                DateTime dt = Convert.ToDateTime(dr["pDate"]);
                TreeNode tn = new TreeNode(String.Format("{0:dd-MMM-yyyy}", dt));

                foreach (DataRow drChild in dr.GetChildRows("Regsd"))

                    TreeNode childTn = new TreeNode(drChild["pId"].ToString() + "- " + drChild["pName"].ToString());
                    childTn.Tag = drChild["pId"];



[no name] 24-Mar-13 18:27pm
You need to research "lazy loading".
Garth J Lancaster 24-Mar-13 21:01pm
is that akin to 'load only the top level nodes' to start with, then load the sub-levels as they are clicked on ? thats what I was thinking

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900