Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TreeView problem

Status
Not open for further replies.

cyrus71

Programmer
Feb 6, 2006
34
SE
Hi,

I have a UserControl that contains a TreeView(with nodes) , a TextBox and a Button,

I want that when you click on the button you would add a new TreeNode under the selected node that it's name is the text of the TextBox.

I have tryed a lot but no success, I need som code, thanks
 
in your button click event:

Code:
TreeNode newNode = new TreeNode();
newNode.Text = txtName.Text;

tvTreeView.SelectedNode.Nodes.Add(newNode);

tvTreeView.SelectedNode = newNode;

The last line is optional, it sets the newly added node to the selected node. You may want to keep the selection the way it is. its up to you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top