We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Delete Node

Hi Guru, How can i delete a current selected node at run time? I didnt find any function like treeview.DeleteNode(index).... something like this???? Thanks Satish

5 Replies

AD Administrator Syncfusion Team June 15, 2004 12:24 PM UTC

Hi Satish, Please try this this.treeViewAdv1.Nodes.Remove(this.treeViewAdv1.SelectedNode); Let me know if you have any questions. Thanks. Best regards, Stephen. >Hi Guru, >How can i delete a current selected node at run time? I didnt find any function like treeview.DeleteNode(index).... something like this???? >Thanks >Satish


SA Satish June 16, 2004 01:11 AM UTC

Hi Stephen, But the problem in this is, it never deletes the selected row, It will delete the previous selected row if you are using Context Menu to delete the row. Thanks Satish >Hi Satish, > >Please try this > >this.treeViewAdv1.Nodes.Remove(this.treeViewAdv1.SelectedNode); > >Let me know if you have any questions. Thanks. > >Best regards, > >Stephen. > >>Hi Guru, >>How can i delete a current selected node at run time? I didnt find any function like treeview.DeleteNode(index).... something like this???? >>Thanks >>Satish


SA Satish June 16, 2004 03:21 AM UTC

Hi Stephen Please find the document that explains in clear. Thanks Satish >Hi Stephen, >But the problem in this is, it never deletes the selected row, It will delete the previous selected row if you are using Context Menu to delete the row. >Thanks >Satish > >>Hi Satish, >> >>Please try this >> >>this.treeViewAdv1.Nodes.Remove(this.treeViewAdv1.SelectedNode); >> >>Let me know if you have any questions. Thanks. >> >>Best regards, >> >>Stephen. >> >>>Hi Guru, >>>How can i delete a current selected node at run time? I didnt find any function like treeview.DeleteNode(index).... something like this???? >>>Thanks >>>Satish DeleteNodeProblem_8093.zip


AD Administrator Syncfusion Team June 17, 2004 12:05 AM UTC

Hi Satish, This line of code: this.treeViewAdv1.Nodes.Remove(this.treeViewAdv1.SelectedNode); will only delete the selected node if it is a root node as TreeViewAdv.Nodes returns the collection of nodes at level 0. The Nodes collection does not contain all the nodes of the tree, but just the level 0 nodes. If the node is in a level greater than 0, it is not deleted as it is not contained in the primary Nodes collection. So you instead call: TreeViewAdv.SelectedNode.Parent.Nodes.Remove(TreeViewAdv.SelectedNode) Refer to the TreeViewAdvDemo sample (Tools\samples\Tree Package\TreeViewAdvDemo). This sample shows how you can use a context menu in conjunction with the TreeViewAdv control. Here is code you can add to the Cut context menu to take care of what you are looking for: private void cutItem_Click(object sender, System.EventArgs e) { //MessageBox.Show("Not Implemented. Only Edit menu is implemented."); this.treeViewAdv1.SelectedNode.Parent.Nodes.Remove(this.treeViewAdv1.SelectedNode); } Regards Arun


SA Satish June 17, 2004 09:13 AM UTC

Hi Arun, I think you didnt get what I was saying. Anyway I have done this using the following code. //Assign the Selected Node tree.SelectedNode = tree.RMouseDownNode; Thanks Satish >Hi Satish, > >This line of code: >this.treeViewAdv1.Nodes.Remove(this.treeViewAdv1.SelectedNode); >will only delete the selected node if it is a root node as TreeViewAdv.Nodes returns the collection of nodes at level 0. The Nodes collection does not contain all the nodes of the tree, but just the level 0 nodes. If the node is in a level greater than 0, it is not deleted as it is not contained in the primary Nodes collection. So you instead call: > >TreeViewAdv.SelectedNode.Parent.Nodes.Remove(TreeViewAdv.SelectedNode) > > >Refer to the TreeViewAdvDemo sample (Tools\samples\Tree Package\TreeViewAdvDemo). This sample shows how you can use a context menu in conjunction with the TreeViewAdv control. > >Here is code you can add to the Cut context menu to take care of what you are looking for: >private void cutItem_Click(object sender, System.EventArgs e) >{ >//MessageBox.Show("Not Implemented. Only Edit menu is implemented."); >this.treeViewAdv1.SelectedNode.Parent.Nodes.Remove(this.treeViewAdv1.SelectedNode); >} > >Regards >Arun

Loader.
Live Chat Icon For mobile
Up arrow icon