Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#3.5
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()
    {
 
    treeView1.Nodes.Clear();
 
        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"];
                    tn.Nodes.Add(childTn);
 
                }
 
                root.Nodes.Add(tn);
                root.Expand();      
 
            }
}
Posted 24-Mar-13 13:17pm
Comments
ThePhantomUpvoter at 24-Mar-13 18:27pm
   
You need to research "lazy loading".
Garth J Lancaster at 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)

  Print Answers RSS
0 Mathew Soji 334
1 Maciej Los 295
2 BillWoodruff 290
3 Afzaal Ahmad Zeeshan 257
4 DamithSL 225
0 OriginalGriff 6,369
1 Sergey Alexandrovich Kryukov 5,973
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 4,045


Advertise | Privacy | Mobile
Web04 | 2.8.1411019.1 | Last Updated 24 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100