Click here to Skip to main content
15,902,926 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to add child node on button click event....
Posted

treeview1.n0des(0).nodes.add("")
 
Share this answer
 
VB
Private Sub addParentNode_Button_Click(sender As Object, e As EventArgs)
	treeView2.BeginUpdate()
	'treeView2.Nodes.Clear();
	Dim yourParentNode As String
	yourParentNode = textBox1.Text.Trim()
	treeView2.Nodes.Add(yourParentNode)
	treeView2.EndUpdate()
End Sub

Private Sub addChildNode_Button_Click(sender As Object, e As EventArgs)
	If treeView2.SelectedNode IsNot Nothing Then
		Dim yourChildNode As String
		yourChildNode = textBox1.Text.Trim()
		treeView2.SelectedNode.Nodes.Add(yourChildNode)
		treeView2.ExpandAll()
	End If
End Sub

convert above code in c#.net
 
Share this answer
 
To add or remove nodes in the designer

Select the TreeView control or add one to the form.
In the Properties window, click the ellipsis () button next to the Nodes property.
The TreeNode Editor appears.

To add nodes, a root node must exist; if one does not exist, you must first add a root by clicking the Add Root button. You can then add child nodes by selecting the root or any other node and clicking the Add Child button. To delete nodes, select the node to delete and then click the Delete button.
To add nodes programmatically

Use the Add method of the tree view's Nodes property.
Copy
' Visual Basic
' Adds new node as a child node of the currently selected node.
Dim newNode As TreeNode = New TreeNode("Text for new node")
TreeView1.SelectedNode.Nodes.Add(newNode)

// C#
// Adds new node as a child node of the currently selected node.
TreeNode newNode = new TreeNode("Text for new node");
treeView1.SelectedNode.Nodes.Add(newNode);

// C++
// Adds new node as a child node of the currently selected node.
TreeNode * newNode = new TreeNode(S"Text for new node");
treeView1->SelectedNode->Nodes->Add(newNode);
To remove nodes programmatically

Use the Remove method of the tree view's Nodes property to remove a single node, or the Clear method to clear all nodes.
Copy
' Visual Basic
' Removes currently selected node, or root if nothing is selected.
TreeView1.Nodes.Remove(TreeView1.SelectedNode)
' Clears all nodes.
TreeView1.Nodes.Clear()

// C#
// Removes currently selected node, or root if nothing
// is selected.
treeView1.Nodes.Remove(treeView1.SelectedNode);
// Clears all nodes.
TreeView1.Nodes.Clear();

// C++
// Removes currently selected node, or root if nothing
// is selected.
treeView1->Nodes->Remove(treeView1->SelectedNode);
// Clears all nodes.
treeView1->Nodes->Clear();
 
Share this answer
 
Comments
najam saqib 28-Mar-16 8:38am    
can'nt be supported

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