ITCOOKBOOK.com

 Options

Current Time:
Thu Sep 09, 2010 10:36 am
View unanswered posts

Log in

Username:
Password:
Log me on automatically each visit

Topic Information

“Treeview” node

 
Post new topic   Reply to topic    ITCOOKBOOK.com Forum Index -> C#
View previous topic :: View next topic  
Author Message
ted
Fresher


Joined: 30 Nov 2006
Posts: 14

PostPosted: Fri Dec 01, 2006 9:14 pm    Post subject: “Treeview” node Reply with quote

I created a lazy loading treeview. The tree only has 2 levels. I allow loading the first level. The second is loaded only if the user expands it. To make the ‘plus’ appear for nodes that contains ‘children’, I add one node with an empty string under each first level node. The only code that deals with expanding and collapsing a node is in the “MouseDown” event. Sometimes, the node won't collapse but it would clear the ‘child’ nodes and add one blank text node.

Code:
        private void phoneTree_MouseDown(object sender, MouseEventArgs e)
        {
            System.Windows.Forms.TreeView tv = (System.Windows.Forms.TreeView)sender;
            System.Windows.Forms.TreeNode n = tv.GetNodeAt(e.X, e.Y);
            System.Windows.Forms.TreeNode childNode;
            System.Data.DataTable dt;
            System.Data.DataRow dRow;
            string[] values;
            int i;

            if (n != null && n.Level == 0)
            {
                n.Nodes.Clear();

                values = n.Tag.ToString().Split('_');

                if (int.Parse(values[1]) > 0)//node has sublevels
                {
                    if (!n.IsExpanded)
                    {
                        dt = fill in data table;

                        for (i = 0; i < dt.Rows.Count; i++)
                        {
                            dRow = dt.Rows[i];

                            childNode = new System.Windows.Forms.TreeNode();
                            childNode.Tag = string.Format("{0}_0", dRow["ID"]);//ID_hasChildren
                            childNode.Text = dRow["Desc"].ToString();

                            n.Nodes.Add(childNode);
                        }
                    }
                    else
                    {
                        n.Nodes.Clear();

                        childNode = new System.Windows.Forms.TreeNode();
                        n.Nodes.Add(childNode);
                    }
                }
            }
        }

_________________
Ted Schmidt
"Carpe Diem!"
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    ITCOOKBOOK.com Forum Index -> C# All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Help US Help YOU

 

 

Please complete our short survey and save $17.50 on ITCOOKBOOK.COM.

 

 

Take a look at SAPTrends.com, a new blog dedicated to discussion of SAP Training trends in SAP ERP.

 

 

C# Interview Questions

 

.NET Interview Questions

 

Java Interview Questions

 

Python Interview Questions

 

ColdFusion Interview Questions

 

Linux Interview Questions

 

Linux LPIC 1 Certification Questions

 

Perl Programming Interview Questions