Collapsing all child nodes of a parent node in a tree view control

Hi, I got a tree control where the order of nodes is three, i.e Parent node---->First child node----> n child nodes of First child node. i want to collapse all the child nodes of FirstChildNode. when i select any one of the child nodes , except the selcted node all the other child nodes should be closed. iam doing like this in treenode_select() event this.treJob.TopVisibleNode.FirstNode.CollapseAll(); this.treJob.TopVisibleNode.FirstNode.Expand(); but iam not successfull any clues.... regards seash

7 Replies

AD Administrator Syncfusion Team June 29, 2004 04:59 PM UTC

Hi Seash Here is a code snippet that demonstrates how when you right click on a node in a TreeViewAdv control and if it is not a top level node, it''s child nodes are collapsed: private void treeViewAdv1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { if ((e.Button == MouseButtons.Right)&& (this.treeViewAdv1.SelectedNode.Level!=1)) { if ((this.treeViewAdv1.SelectedNode.HasChildren)) { this.treeViewAdv1.SelectedNode.CollapseAll(); } else { MessageBox.Show("The selected node has no child nodes"); } } } This should give you an idea to do what you are seeking. Regards Arun


SA Satish June 30, 2004 04:48 AM UTC

Hi Arun, I just spoke to Seash. I made document what Seash whats in the TreeView. Please find the document. Thanks Satish >Hi Seash > >Here is a code snippet that demonstrates how when you right click on a node in a TreeViewAdv control and if it is not a top level node, it''s child nodes are collapsed: > >private void treeViewAdv1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) >{ > if ((e.Button == MouseButtons.Right)&& (this.treeViewAdv1.SelectedNode.Level!=1)) > { > if ((this.treeViewAdv1.SelectedNode.HasChildren)) > { > this.treeViewAdv1.SelectedNode.CollapseAll(); > } > else > { > MessageBox.Show("The selected node has no child nodes"); > } > } >} > >This should give you an idea to do what you are seeking. > >Regards >Arun > TreeError_4660.zip


SA Satish July 1, 2004 12:02 PM UTC

Hi Arun, Please hightlight the solution. Thanks Satish >Hi Arun, >I just spoke to Seash. I made document what Seash whats in the TreeView. >Please find the document. >Thanks >Satish > >>Hi Seash >> >>Here is a code snippet that demonstrates how when you right click on a node in a TreeViewAdv control and if it is not a top level node, it''s child nodes are collapsed: >> >>private void treeViewAdv1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) >>{ >> if ((e.Button == MouseButtons.Right)&& (this.treeViewAdv1.SelectedNode.Level!=1)) >> { >> if ((this.treeViewAdv1.SelectedNode.HasChildren)) >> { >> this.treeViewAdv1.SelectedNode.CollapseAll(); >> } >> else >> { >> MessageBox.Show("The selected node has no child nodes"); >> } >> } >>} >> >>This should give you an idea to do what you are seeking. >> >>Regards >>Arun >> > >TreeError_4660.zip > >


AD Administrator Syncfusion Team July 1, 2004 03:39 PM UTC

Hi Satish Here you go: private void treeViewAdv1_AfterSelect(object sender, System.EventArgs e) { if ((this.treeViewAdv1.SelectedNode.Level==1)&&(this.treeViewAdv1.SelectedNode.HasChildren) &&(this.treeViewAdv1.SelectedNode.Expanded)) { this.treeViewAdv1.CollapseAll(); this.treeViewAdv1.SelectedNode.ExpandAll(); } } Regards Arun


SA Satish July 2, 2004 01:30 AM UTC

Hi Arun, The code you have mentioned below is not working. I want to achive same resuls as i posted the document in form. Thanks Satish >Hi Satish >Here you go: >private void treeViewAdv1_AfterSelect(object sender, System.EventArgs e) >{ > if ((this.treeViewAdv1.SelectedNode.Level==1)&&(this.treeViewAdv1.SelectedNode.HasChildren) > &&(this.treeViewAdv1.SelectedNode.Expanded)) > { > this.treeViewAdv1.CollapseAll(); > this.treeViewAdv1.SelectedNode.ExpandAll(); > } >} > >Regards >Arun >


AD Administrator Syncfusion Team July 2, 2004 05:16 PM UTC

Hi Satish Here is a sample that does what you are looking for. This is the relevant code from the sample: bool b = false; private void treeViewAdv1_AfterSelect(object sender, System.EventArgs e) { if ((this.treeViewAdv1.SelectedNode.Level==1)&&(this.treeViewAdv1.SelectedNode.HasChildren))//&&(this.treeViewAdv1.SelectedNode.Expanded)) { this.treeViewAdv1.CollapseAll(); this.treeViewAdv1.SelectedNode.ExpandAll(); } } private void treeViewAdv1_AfterExpand(object sender, Syncfusion.Windows.Forms.Tools.TreeViewAdvNodeEventArgs e) { if (b) { b = false; this.treeViewAdv1.CollapseAll(); e.Node.ExpandAll(); this.treeViewAdv1.SelectedNode = e.Node; } b = true; } We would really appreciate it if you could use Direct-Trac for specific issues like this in future. Regards Arun


AD Administrator Syncfusion Team July 2, 2004 05:17 PM UTC

Hi Satish Here is a link to the sample. Regards Arun

Loader.
Up arrow icon